mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 08:16:07 +00:00
optimize get all share links from db (#5802)
This commit is contained in:
@@ -178,6 +178,15 @@ class ShareLinks(APIView):
|
||||
1. default(NOT guest) user;
|
||||
"""
|
||||
|
||||
try:
|
||||
current_page = int(request.GET.get('page', '1'))
|
||||
per_page = int(request.GET.get('per_page', '25'))
|
||||
except ValueError:
|
||||
current_page = 1
|
||||
per_page = 25
|
||||
|
||||
offset = per_page * (current_page - 1)
|
||||
|
||||
username = request.user.username
|
||||
|
||||
repo_id = request.GET.get('repo_id', '')
|
||||
@@ -186,7 +195,7 @@ class ShareLinks(APIView):
|
||||
fileshares = []
|
||||
# get all share links of current user
|
||||
if not repo_id and not path:
|
||||
fileshares = FileShare.objects.filter(username=username)
|
||||
fileshares = FileShare.objects.filter(username=username)[offset:offset + per_page]
|
||||
|
||||
# share links in repo
|
||||
if repo_id and not path:
|
||||
@@ -196,7 +205,7 @@ class ShareLinks(APIView):
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
fileshares = FileShare.objects.filter(username=username) \
|
||||
.filter(repo_id=repo_id)
|
||||
.filter(repo_id=repo_id)[offset:offset + per_page]
|
||||
|
||||
# share links by repo and path
|
||||
if repo_id and path:
|
||||
@@ -218,7 +227,7 @@ class ShareLinks(APIView):
|
||||
|
||||
fileshares = FileShare.objects.filter(username=username) \
|
||||
.filter(repo_id=repo_id) \
|
||||
.filter(path=path)
|
||||
.filter(path=path)[offset:offset + per_page]
|
||||
|
||||
repo_object_dict = {}
|
||||
repo_folder_permission_dict = {}
|
||||
@@ -1456,7 +1465,7 @@ class ShareLinksCleanInvalid(APIView):
|
||||
username = request.user.username
|
||||
share_links = FileShare.objects.filter(username=username)
|
||||
|
||||
for share_link in share_links:
|
||||
for share_link in share_links.iterator(chunk_size=1000):
|
||||
|
||||
if share_link.is_expired():
|
||||
share_link.delete()
|
||||
|
@@ -597,21 +597,6 @@ def view_lib_file(request, repo_id, path):
|
||||
return_dict['locked_by_me'] = locked_by_me
|
||||
return_dict['can_lock_unlock_file'] = can_lock_unlock_file
|
||||
|
||||
# file shared link
|
||||
l = FileShare.objects.filter(repo_id=repo_id).filter(
|
||||
username=username).filter(path=path)
|
||||
fileshare = l[0] if len(l) > 0 else None
|
||||
file_shared_link = gen_file_share_link(fileshare.token) if fileshare else ''
|
||||
|
||||
return_dict['fileshare'] = fileshare,
|
||||
return_dict['file_shared_link'] = file_shared_link
|
||||
|
||||
if parse_repo_perm(permission).can_download and \
|
||||
request.user.permissions.can_generate_share_link():
|
||||
return_dict['can_share_file'] = True
|
||||
else:
|
||||
return_dict['can_share_file'] = False
|
||||
|
||||
# fetch file contributors and latest contributor
|
||||
try:
|
||||
# get real path for sub repo
|
||||
|
@@ -69,15 +69,6 @@ def is_no_quota(repo_id):
|
||||
return True if seaserv.check_quota(repo_id) < 0 else False
|
||||
|
||||
|
||||
def get_fileshare(repo_id, username, path):
|
||||
if path == '/': # no shared link for root dir
|
||||
return None
|
||||
|
||||
share_list = FileShare.objects.filter(repo_id=repo_id).filter(
|
||||
username=username).filter(path=path)
|
||||
return share_list[0] if len(share_list) > 0 else None
|
||||
|
||||
|
||||
def get_dir_share_link(fileshare):
|
||||
# dir shared link
|
||||
if fileshare:
|
||||
|
Reference in New Issue
Block a user