Skip to content

Commit

Permalink
code-optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
r350178982 committed Jul 2, 2024
1 parent 4729cee commit adef5e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 3 additions & 7 deletions seahub/api2/endpoints/repo_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from seahub.api2.utils import api_error

from seahub.signals import clean_up_repo_trash
from seahub.utils import get_trash_records
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
from seahub.utils.repo import get_repo_owner, is_repo_admin
from seahub.views import check_folder_permission
Expand Down Expand Up @@ -382,17 +383,12 @@ def post(self, request, repo_id, format=None):
show_time = show_days

try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
deleted_entries = seafevents_api.get_delete_records(session, repo_id, show_time, path)
session.close()
deleted_entries = get_trash_records(repo_id, show_time, path)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
pass


items = []
if len(deleted_entries) >= 1:
# sort entry by delete time
Expand Down
8 changes: 7 additions & 1 deletion seahub/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ def get_user_traffic_by_month(username, month):

def get_file_history_suffix():
return seafevents_api.get_file_history_suffix(parsed_events_conf)

def get_trash_records(repo_id, show_time, path):
with _get_seafevents_session() as session:
res = seafevents_api.get_delete_records(session, repo_id, show_time, path)
return res

else:
parsed_events_conf = None
Expand Down Expand Up @@ -874,14 +879,15 @@ def get_file_scan_record():
pass
def get_user_activities_by_timestamp():
pass
def get_trash_records():
pass


def calc_file_path_hash(path, bits=12):
if isinstance(path, str):
path = path.encode('UTF-8')

path_hash = hashlib.md5(urllib.parse.quote(path)).hexdigest()[:bits]

return path_hash

def get_service_url():
Expand Down

0 comments on commit adef5e2

Please sign in to comment.