mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-07 02:10:23 +00:00
perf: 优化 connect method acls 和登录 acls
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import re
|
||||
from django.templatetags.static import static
|
||||
from collections import OrderedDict
|
||||
from itertools import chain
|
||||
import logging
|
||||
import datetime
|
||||
import uuid
|
||||
from functools import wraps
|
||||
import time
|
||||
import ipaddress
|
||||
import psutil
|
||||
import platform
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from functools import wraps
|
||||
from itertools import chain
|
||||
|
||||
import psutil
|
||||
from django.conf import settings
|
||||
from django.templatetags.static import static
|
||||
|
||||
UUID_PATTERN = re.compile(r'\w{8}(-\w{4}){3}-\w{12}')
|
||||
ipip_db = None
|
||||
@@ -76,6 +76,7 @@ def setattr_bulk(seq, key, value):
|
||||
def set_attr(obj):
|
||||
setattr(obj, key, value)
|
||||
return obj
|
||||
|
||||
return map(set_attr, seq)
|
||||
|
||||
|
||||
@@ -97,12 +98,12 @@ def capacity_convert(size, expect='auto', rate=1000):
|
||||
rate_mapping = (
|
||||
('K', rate),
|
||||
('KB', rate),
|
||||
('M', rate**2),
|
||||
('MB', rate**2),
|
||||
('G', rate**3),
|
||||
('GB', rate**3),
|
||||
('T', rate**4),
|
||||
('TB', rate**4),
|
||||
('M', rate ** 2),
|
||||
('MB', rate ** 2),
|
||||
('G', rate ** 3),
|
||||
('GB', rate ** 3),
|
||||
('T', rate ** 4),
|
||||
('TB', rate ** 4),
|
||||
)
|
||||
|
||||
rate_mapping = OrderedDict(rate_mapping)
|
||||
@@ -117,7 +118,7 @@ def capacity_convert(size, expect='auto', rate=1000):
|
||||
|
||||
if expect == 'auto':
|
||||
for unit, rate_ in rate_mapping.items():
|
||||
if rate > std_size/rate_ >= 1 or unit == "T":
|
||||
if rate > std_size / rate_ >= 1 or unit == "T":
|
||||
expect = unit
|
||||
break
|
||||
|
||||
@@ -195,6 +196,7 @@ def with_cache(func):
|
||||
res = func(*args, **kwargs)
|
||||
cache[key] = res
|
||||
return res
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -216,6 +218,7 @@ def timeit(func):
|
||||
msg = "End call {}, using: {:.1f}ms".format(name, using)
|
||||
logger.debug(msg)
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -310,7 +313,7 @@ class Time:
|
||||
def print(self):
|
||||
last, *timestamps = self._timestamps
|
||||
for timestamp, msg in zip(timestamps, self._msgs):
|
||||
logger.debug(f'TIME_IT: {msg} {timestamp-last}')
|
||||
logger.debug(f'TIME_IT: {msg} {timestamp - last}')
|
||||
last = timestamp
|
||||
|
||||
|
||||
@@ -367,7 +370,7 @@ def pretty_string(data, max_length=128, ellipsis_str='...'):
|
||||
|
||||
|
||||
def group_by_count(it, count):
|
||||
return [it[i:i+count] for i in range(0, len(it), count)]
|
||||
return [it[i:i + count] for i in range(0, len(it), count)]
|
||||
|
||||
|
||||
def test_ip_connectivity(host, port, timeout=0.5):
|
||||
@@ -395,3 +398,17 @@ def static_or_direct(logo_path):
|
||||
def make_dirs(name, mode=0o755, exist_ok=False):
|
||||
""" 默认权限设置为 0o755 """
|
||||
return os.makedirs(name, mode=mode, exist_ok=exist_ok)
|
||||
|
||||
|
||||
def distinct(seq, key=None):
|
||||
if key is None:
|
||||
# 如果未提供关键字参数,则默认使用元素本身作为比较键
|
||||
key = lambda x: x
|
||||
seen = set()
|
||||
result = []
|
||||
for item in seq:
|
||||
k = key(item)
|
||||
if k not in seen:
|
||||
seen.add(k)
|
||||
result.append(item)
|
||||
return result
|
||||
|
Reference in New Issue
Block a user