mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 08:53:14 +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 React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
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';
|
import { Utils } from '../../utils/utils';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
@@ -80,7 +80,7 @@ class MylibRepoMenu extends React.Component {
|
|||||||
if (this.props.isPC && enableRepoSnapshotLabel) {
|
if (this.props.isPC && enableRepoSnapshotLabel) {
|
||||||
operations.push('Label Current State');
|
operations.push('Label Current State');
|
||||||
}
|
}
|
||||||
if (isPro) {
|
if (enableRepoAutoDel) {
|
||||||
operations.push('Old Files Auto Delete');
|
operations.push('Old Files Auto Delete');
|
||||||
}
|
}
|
||||||
return operations;
|
return operations;
|
||||||
|
@@ -20,6 +20,7 @@ export const serviceURL = window.app.config.serviceURL;
|
|||||||
export const appAvatarURL = window.app.config.avatarURL;
|
export const appAvatarURL = window.app.config.avatarURL;
|
||||||
export const faviconPath = window.app.config.faviconPath;
|
export const faviconPath = window.app.config.faviconPath;
|
||||||
export const loginBGPath = window.app.config.loginBGPath;
|
export const loginBGPath = window.app.config.loginBGPath;
|
||||||
|
export const enableRepoAutoDel = window.app.config.enableRepoAutoDel;
|
||||||
|
|
||||||
//pageOptions
|
//pageOptions
|
||||||
export const trashReposExpireDays = window.app.pageOptions.trashReposExpireDays;
|
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.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:
|
try:
|
||||||
from seahub.settings import MULTI_TENANCY
|
from seahub.settings import MULTI_TENANCY
|
||||||
@@ -154,6 +154,7 @@ def base(request):
|
|||||||
'terms_of_service_link': TERMS_OF_SERVICE_LINK,
|
'terms_of_service_link': TERMS_OF_SERVICE_LINK,
|
||||||
'side_nav_footer_custom_html': SIDE_NAV_FOOTER_CUSTOM_HTML,
|
'side_nav_footer_custom_html': SIDE_NAV_FOOTER_CUSTOM_HTML,
|
||||||
'about_dialog_custom_html': ABOUT_DIALOG_CUSTOM_HTML,
|
'about_dialog_custom_html': ABOUT_DIALOG_CUSTOM_HTML,
|
||||||
|
'enable_repo_auto_del': ENABLE_REPO_AUTO_DEL,
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.user.is_staff:
|
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)
|
dirents = seafile_api.list_dir_by_path(repo_id, path)
|
||||||
|
|
||||||
|
del_dirents = list()
|
||||||
for dirent in dirents:
|
for dirent in dirents:
|
||||||
|
|
||||||
if stat.S_ISDIR(dirent.mode):
|
if stat.S_ISDIR(dirent.mode):
|
||||||
iterate_and_del_files_recursively(repo_id,
|
iterate_and_del_files_recursively(repo_id, os.path.join(path, dirent.obj_name), days)
|
||||||
os.path.join(path, dirent.obj_name),
|
else:
|
||||||
days)
|
mtime = dirent.mtime
|
||||||
continue
|
cur_time = int(time.time())
|
||||||
|
time_delta = days * 24 * 60 * 60
|
||||||
mtime = dirent.mtime
|
if cur_time - time_delta > mtime:
|
||||||
cur_time = int(time.time())
|
del_dirents.append(dirent.obj_name)
|
||||||
time_delta = days * 24 * 60 * 60
|
if del_dirents:
|
||||||
if cur_time - time_delta > mtime:
|
try:
|
||||||
file_full_path = os.path.join(path, dirent.obj_name)
|
seafile_api.del_file(repo_id, path, json.dumps(del_dirents), 'seafevents')
|
||||||
seafile_api.del_file(repo_id, path,
|
except Exception as e:
|
||||||
json.dumps([dirent.obj_name]),
|
logger.error('Failed to delete files in repo: %s, path: %s, error: %s' % (repo_id, path, e))
|
||||||
'seafevents')
|
|
||||||
logger.info('{} of {} deleted at {}.'.format(file_full_path, repo_id, cur_time))
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@@ -47,6 +47,7 @@
|
|||||||
isDocs: '{{ is_docs }}',
|
isDocs: '{{ is_docs }}',
|
||||||
lang: '{{ LANGUAGE_CODE }}',
|
lang: '{{ LANGUAGE_CODE }}',
|
||||||
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
||||||
|
enableRepoAutoDel: {% if enable_repo_auto_del %} true {% else %} false {% endif %},
|
||||||
useGoFileserver: {% if USE_GO_FILESERVER %} true {% else %} false {% endif %},
|
useGoFileserver: {% if USE_GO_FILESERVER %} true {% else %} false {% endif %},
|
||||||
serviceURL: '{{ service_url }}',
|
serviceURL: '{{ service_url }}',
|
||||||
seafileVersion: '{{ seafile_version }}',
|
seafileVersion: '{{ seafile_version }}',
|
||||||
|
@@ -1171,6 +1171,21 @@ if EVENTS_CONFIG_FILE:
|
|||||||
|
|
||||||
HAS_FILE_SEARCH = check_search_enabled()
|
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):
|
def is_user_password_strong(password):
|
||||||
"""Return ``True`` if user's password is STRONG, otherwise ``False``.
|
"""Return ``True`` if user's password is STRONG, otherwise ``False``.
|
||||||
|
Reference in New Issue
Block a user