1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-05-13 10:34:44 +00:00

Add repo sort function

This commit is contained in:
杨赫然 2019-12-30 16:19:33 +08:00
parent 28223c17a3
commit 3230c31dff
11 changed files with 124 additions and 12 deletions

View File

@ -261,12 +261,34 @@ seafile_pop_event(const char *channel, GError **error)
}
#endif
static gint
comp_repo_size_func (gconstpointer a, gconstpointer b)
{
const SeafRepo *repo_a = a, *repo_b = b;
return (repo_a->size - repo_b->size);
}
static gint
comp_repo_file_count_func (gconstpointer a, gconstpointer b)
{
const SeafRepo *repo_a = a, *repo_b = b;
return (repo_a->file_count - repo_b->file_count);
}
GList*
seafile_get_repo_list (int start, int limit, GError **error)
seafile_get_repo_list (int start, int limit, const char *order_by, GError **error)
{
GList *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, start, limit);
GList *ret = NULL;
if (g_strcmp0 (order_by, "size") == 0) {
repos = g_list_sort (repos, comp_repo_size_func);
} else if (g_strcmp0 (order_by, "file_count") == 0) {
repos = g_list_sort (repos, comp_repo_file_count_func);
}
ret = convert_repo_list (repos);
#ifdef SEAFILE_SERVER
@ -3122,6 +3144,12 @@ seafile_check_quota (const char *repo_id, gint64 delta, GError **error)
return rc;
}
GList *
seafile_list_user_quota_usage (GError **error)
{
return seaf_repo_quota_manager_list_user_quota_usage (seaf->quota_mgr);
}
static char *
get_obj_id_by_path (const char *repo_id,
const char *path,

View File

@ -17,7 +17,7 @@ seafile_get_session_info (GError **error);
*
* Returns repository list.
*/
GList* seafile_get_repo_list (int start, int limit, GError **error);
GList* seafile_get_repo_list (int start, int limit, const char *order_by, GError **error);
gint64
seafile_count_repos (GError **error);
@ -815,6 +815,9 @@ seafile_get_user_quota (const char *user, GError **error);
int
seafile_check_quota (const char *repo_id, gint64 delta, GError **error);
GList *
seafile_list_user_quota_usage (GError **error);
char *
seafile_get_file_id_by_path (const char *repo_id, const char *path,
GError **error);

View File

@ -204,4 +204,9 @@ public class EncryptionInfo: Object {
public string salt { get; set; }
}
public class UserQuotaUsage: Object {
public string user { get; set; }
public int64 usage { get; set; }
}
} // namespace

View File

@ -74,6 +74,7 @@ func_table = [
[ "objlist", ["int", "int"] ],
[ "objlist", ["int", "string"] ],
[ "objlist", ["int", "int", "int"] ],
[ "objlist", ["int", "int", "string"] ],
[ "objlist", ["string"] ],
[ "objlist", ["string", "int"] ],
[ "objlist", ["string", "int", "int"] ],

View File

@ -27,7 +27,7 @@ class SeafServerThreadedRpcClient(NamedPipeClient):
remove_repo = seafile_destroy_repo
@searpc_func("objlist", ["int", "int"])
def seafile_get_repo_list(start, limit):
def seafile_get_repo_list(start, limit, order_by):
pass
get_repo_list = seafile_get_repo_list
@ -464,6 +464,10 @@ class SeafServerThreadedRpcClient(NamedPipeClient):
def check_quota(repo_id, delta):
pass
@searpc_func("objlist", [])
def list_user_quota_usage():
pass
# password management
@searpc_func("int", ["string", "string"])
def seafile_check_passwd(repo_id, magic):

View File

@ -101,11 +101,11 @@ class SeafileAPI(object):
def remove_repo(self, repo_id):
return seafserv_threaded_rpc.remove_repo(repo_id)
def get_repo_list(self, start, limit):
def get_repo_list(self, start, limit, order_by):
"""
Return: a list of Repo objects (lib/repo.vala)
"""
return seafserv_threaded_rpc.get_repo_list(start, limit)
return seafserv_threaded_rpc.get_repo_list(start, limit, order_by)
def count_repos(self):
return seafserv_threaded_rpc.count_repos()
@ -726,6 +726,9 @@ class SeafileAPI(object):
def check_quota(self, repo_id, delta=0):
return seafserv_threaded_rpc.check_quota(repo_id, delta)
def list_user_quota_usage(self):
return seafserv_threaded_rpc.list_user_quota_usage()
# virtual repo
def create_virtual_repo(self, origin_repo_id, path, repo_name, repo_desc, owner, passwd=''):
return seafserv_threaded_rpc.create_virtual_repo(origin_repo_id,

View File

@ -565,3 +565,53 @@ seaf_quota_manager_get_org_user_usage (SeafQuotaManager *mgr,
return seaf_db_statement_get_int64 (mgr->session->db, sql,
2, "int", org_id, "string", user);
}
static gboolean
collect_user_and_usage (SeafDBRow *row, void *data)
{
GList **p = data;
const char *user;
gint64 usage;
user = seaf_db_row_get_column_text (row, 0);
usage = seaf_db_row_get_column_int64 (row, 1);
if (!user)
return FALSE;
SeafileUserQuotaUsage *user_usage= g_object_new (SEAFILE_TYPE_USER_QUOTA_USAGE,
"user", user,
"usage", usage,
NULL);
if (!user_usage)
return FALSE;
*p = g_list_prepend (*p, user_usage);
return TRUE;
}
GList *
seaf_repo_quota_manager_list_user_quota_usage (SeafQuotaManager *mgr)
{
GList *ret = NULL;
char *sql = NULL;
sql = "SELECT owner_id,SUM(size) FROM "
"RepoOwner o LEFT JOIN VirtualRepo v ON o.repo_id=v.repo_id, "
"RepoSize WHERE "
"o.repo_id=RepoSize.repo_id "
"AND v.repo_id IS NULL";
if (seaf_db_statement_foreach_row (mgr->session->db, sql,
collect_user_and_usage,
&ret, 0) < 0) {
while (ret) {
g_object_unref (ret->data);
ret = g_list_delete_link (ret, ret);
}
return NULL;
}
return g_list_reverse (ret);
}

View File

@ -50,4 +50,7 @@ seaf_quota_manager_check_quota_with_delta (SeafQuotaManager *mgr,
gint64
seaf_quota_manager_get_user_usage (SeafQuotaManager *mgr, const char *user);
GList *
seaf_repo_quota_manager_list_user_quota_usage (SeafQuotaManager *mgr);
#endif

View File

@ -78,7 +78,7 @@ static void start_rpc_service (const char *seafile_dir)
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_repo_list,
"seafile_get_repo_list",
searpc_signature_objlist__int_int());
searpc_signature_objlist__int_int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_count_repos,
"seafile_count_repos",
@ -609,6 +609,10 @@ static void start_rpc_service (const char *seafile_dir)
seafile_check_quota,
"check_quota",
searpc_signature_int__string_int64());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_list_user_quota_usage,
"list_user_quota_usage",
searpc_signature_objlist__void());
/* repo permission */
searpc_server_register_function ("seafserv-threaded-rpcserver",

View File

@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
@retry(wait=wait_fixed(2), stop=stop_after_attempt(10))
def wait_for_server():
seafile_api.get_repo_list(0, 1)
seafile_api.get_repo_list(0, 1, None)
@pytest.fixture(scope='session', autouse=True)

View File

@ -2,6 +2,10 @@ import pytest
from tests.config import USER, USER2
from seaserv import seafile_api as api
def get_repo_list_order_by(t_start, t_limit, order_by):
t_repo_list = api.get_repo_list(t_start, t_limit, order_by)
assert t_repo_list and len(t_repo_list)
def test_repo_manipulation():
#test get_system_default_repo_id
@ -66,14 +70,21 @@ def test_repo_manipulation():
assert t_enc_repo_id == '826d1b7b-f110-46f2-8d5e-7b5ac3e11f4d'
#test get_repo_list
t_start = -1;
t_limit = -1;
t_repo_list = api.get_repo_list(t_start, t_limit)
assert t_repo_list and len(t_repo_list)
#test order by None
order_by = None
get_repo_list_order_by(-1 ,-1, order_by)
#test order by size
order_by = "size"
get_repo_list_order_by(-1 ,-1, order_by)
#test order by file_count
order_by = "file_count"
get_repo_list_order_by(-1 ,-1, order_by)
t_start = 1;
t_limit = 1;
t_repo_list = api.get_repo_list(t_start, t_limit)
t_repo_list = api.get_repo_list(t_start, t_limit, None)
assert t_repo_list and len(t_repo_list) == 1
#test get_owned_repo_list