mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
optimize auto delete (#5245)
* use batch delete files * check enabled_repo_auto_del via seafevents config * fix code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
||||
import { gettext, isPro, folderPermEnabled, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured } from '../../utils/constants';
|
||||
import { gettext, isPro, folderPermEnabled, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured, enableRepoAutoDel } from '../../utils/constants';
|
||||
import { Utils } from '../../utils/utils';
|
||||
|
||||
const propTypes = {
|
||||
@@ -80,7 +80,7 @@ class MylibRepoMenu extends React.Component {
|
||||
if (this.props.isPC && enableRepoSnapshotLabel) {
|
||||
operations.push('Label Current State');
|
||||
}
|
||||
if (isPro) {
|
||||
if (enableRepoAutoDel) {
|
||||
operations.push('Old Files Auto Delete');
|
||||
}
|
||||
return operations;
|
||||
|
@@ -20,6 +20,7 @@ export const serviceURL = window.app.config.serviceURL;
|
||||
export const appAvatarURL = window.app.config.avatarURL;
|
||||
export const faviconPath = window.app.config.faviconPath;
|
||||
export const loginBGPath = window.app.config.loginBGPath;
|
||||
export const enableRepoAutoDel = window.app.config.enableRepoAutoDel;
|
||||
|
||||
//pageOptions
|
||||
export const trashReposExpireDays = window.app.pageOptions.trashReposExpireDays;
|
||||
|
@@ -32,7 +32,7 @@ from seahub.utils import get_site_name, get_service_url
|
||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||
|
||||
|
||||
from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, is_pro_version
|
||||
from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, is_pro_version, ENABLE_REPO_AUTO_DEL
|
||||
|
||||
try:
|
||||
from seahub.settings import MULTI_TENANCY
|
||||
@@ -154,6 +154,7 @@ def base(request):
|
||||
'terms_of_service_link': TERMS_OF_SERVICE_LINK,
|
||||
'side_nav_footer_custom_html': SIDE_NAV_FOOTER_CUSTOM_HTML,
|
||||
'about_dialog_custom_html': ABOUT_DIALOG_CUSTOM_HTML,
|
||||
'enable_repo_auto_del': ENABLE_REPO_AUTO_DEL,
|
||||
}
|
||||
|
||||
if request.user.is_staff:
|
||||
|
@@ -20,23 +20,22 @@ def iterate_and_del_files_recursively(repo_id, path, days):
|
||||
|
||||
dirents = seafile_api.list_dir_by_path(repo_id, path)
|
||||
|
||||
del_dirents = list()
|
||||
for dirent in dirents:
|
||||
|
||||
if stat.S_ISDIR(dirent.mode):
|
||||
iterate_and_del_files_recursively(repo_id,
|
||||
os.path.join(path, dirent.obj_name),
|
||||
days)
|
||||
continue
|
||||
|
||||
iterate_and_del_files_recursively(repo_id, os.path.join(path, dirent.obj_name), days)
|
||||
else:
|
||||
mtime = dirent.mtime
|
||||
cur_time = int(time.time())
|
||||
time_delta = days * 24 * 60 * 60
|
||||
if cur_time - time_delta > mtime:
|
||||
file_full_path = os.path.join(path, dirent.obj_name)
|
||||
seafile_api.del_file(repo_id, path,
|
||||
json.dumps([dirent.obj_name]),
|
||||
'seafevents')
|
||||
logger.info('{} of {} deleted at {}.'.format(file_full_path, repo_id, cur_time))
|
||||
del_dirents.append(dirent.obj_name)
|
||||
if del_dirents:
|
||||
try:
|
||||
seafile_api.del_file(repo_id, path, json.dumps(del_dirents), 'seafevents')
|
||||
except Exception as e:
|
||||
logger.error('Failed to delete files in repo: %s, path: %s, error: %s' % (repo_id, path, e))
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@@ -47,6 +47,7 @@
|
||||
isDocs: '{{ is_docs }}',
|
||||
lang: '{{ LANGUAGE_CODE }}',
|
||||
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
||||
enableRepoAutoDel: {% if enable_repo_auto_del %} true {% else %} false {% endif %},
|
||||
useGoFileserver: {% if USE_GO_FILESERVER %} true {% else %} false {% endif %},
|
||||
serviceURL: '{{ service_url }}',
|
||||
seafileVersion: '{{ seafile_version }}',
|
||||
|
@@ -1171,6 +1171,21 @@ if EVENTS_CONFIG_FILE:
|
||||
|
||||
HAS_FILE_SEARCH = check_search_enabled()
|
||||
|
||||
# repo auto delete related
|
||||
ENABLE_REPO_AUTO_DEL = False
|
||||
if EVENTS_CONFIG_FILE:
|
||||
def check_repo_auto_del_enabled():
|
||||
enabled = False
|
||||
if hasattr(seafevents, 'is_repo_auto_del_enabled'):
|
||||
enabled = seafevents.is_repo_auto_del_enabled(EVENTS_CONFIG_FILE)
|
||||
if enabled:
|
||||
logging.debug('search: enabled')
|
||||
else:
|
||||
logging.debug('search: not enabled')
|
||||
return enabled
|
||||
|
||||
ENABLE_REPO_AUTO_DEL = check_repo_auto_del_enabled()
|
||||
|
||||
|
||||
def is_user_password_strong(password):
|
||||
"""Return ``True`` if user's password is STRONG, otherwise ``False``.
|
||||
|
Reference in New Issue
Block a user