1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-07 09:54:22 +00:00

Get repo list add return virtual repos (#605)

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks 2023-03-20 10:11:57 +08:00 committed by GitHub
parent 6ca4f18d31
commit ad5ce70ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 40 deletions

View File

@ -263,9 +263,9 @@ seafile_pop_event(const char *channel, GError **error)
#endif #endif
GList* GList*
seafile_get_repo_list (int start, int limit, const char *order_by, GError **error) seafile_get_repo_list (int start, int limit, const char *order_by, int ret_virt_repo, GError **error)
{ {
GList *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, start, limit, order_by); GList *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, start, limit, order_by, ret_virt_repo);
GList *ret = NULL; GList *ret = NULL;
ret = convert_repo_list (repos); ret = convert_repo_list (repos);
@ -565,7 +565,7 @@ seafile_unsync_repos_by_account (const char *server_addr, const char *email, GEr
return -1; return -1;
} }
GList *ptr, *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, -1, -1); GList *ptr, *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, -1, -1, NULL, 0);
if (!repos) { if (!repos) {
return 0; return 0;
} }
@ -602,7 +602,7 @@ seafile_remove_repo_tokens_by_account (const char *server_addr, const char *emai
return -1; return -1;
} }
GList *ptr, *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, -1, -1); GList *ptr, *repos = seaf_repo_manager_get_repo_list(seaf->repo_mgr, -1, -1, NULL, 0);
if (!repos) { if (!repos) {
return 0; return 0;
} }

View File

@ -17,7 +17,7 @@ seafile_get_session_info (GError **error);
* *
* Returns repository list. * Returns repository list.
*/ */
GList* seafile_get_repo_list (int start, int limit, const char *order_by, GError **error); GList* seafile_get_repo_list (int start, int limit, const char *order_by, int ret_virt_repo, GError **error);
gint64 gint64
seafile_count_repos (GError **error); seafile_count_repos (GError **error);

View File

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

View File

@ -31,8 +31,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient):
pass pass
remove_repo = seafile_destroy_repo remove_repo = seafile_destroy_repo
@searpc_func("objlist", ["int", "int"]) @searpc_func("objlist", ["int", "int", "string", "int"])
def seafile_get_repo_list(start, limit, order_by): def seafile_get_repo_list(start, limit, order_by, ret_virt_repo):
pass pass
get_repo_list = seafile_get_repo_list get_repo_list = seafile_get_repo_list

View File

@ -107,11 +107,11 @@ class SeafileAPI(object):
def remove_repo(self, repo_id): def remove_repo(self, repo_id):
return seafserv_threaded_rpc.remove_repo(repo_id) return seafserv_threaded_rpc.remove_repo(repo_id)
def get_repo_list(self, start, limit, order_by=None): def get_repo_list(self, start, limit, order_by=None, ret_virt_repo=False):
""" """
Return: a list of Repo objects (lib/repo.vala) Return: a list of Repo objects (lib/repo.vala)
""" """
return seafserv_threaded_rpc.get_repo_list(start, limit, order_by) return seafserv_threaded_rpc.get_repo_list(start, limit, order_by, 1 if ret_virt_repo else 0)
def count_repos(self): def count_repos(self):
return seafserv_threaded_rpc.count_repos() return seafserv_threaded_rpc.count_repos()

View File

@ -2532,101 +2532,108 @@ seaf_repo_manager_get_repo_id_list (SeafRepoManager *mgr)
} }
GList * GList *
seaf_repo_manager_get_repo_list (SeafRepoManager *mgr, int start, int limit, const char *order_by) seaf_repo_manager_get_repo_list (SeafRepoManager *mgr, int start, int limit, const char *order_by, int ret_virt_repo)
{ {
GList *ret = NULL; GList *ret = NULL;
char *sql_base = NULL;
char sql[512];
int rc; int rc;
GString *sql = g_string_new ("");
if (start == -1 && limit == -1) { if (start == -1 && limit == -1) {
switch (seaf_db_type(mgr->seaf->db)) { switch (seaf_db_type(mgr->seaf->db)) {
case SEAF_DB_TYPE_MYSQL: case SEAF_DB_TYPE_MYSQL:
sql_base = "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, " g_string_append (sql, "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
"i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM " "i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM "
"RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id " "RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id "
"LEFT JOIN Branch b ON i.repo_id = b.repo_id " "LEFT JOIN Branch b ON i.repo_id = b.repo_id "
"LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id " "LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id " "LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id " "LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND " "WHERE r.repo_id IS NOT NULL ");
"v.repo_id IS NULL "; if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
if (g_strcmp0 (order_by, "size") == 0) if (g_strcmp0 (order_by, "size") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY s.size DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY s.size DESC, i.repo_id");
else if (g_strcmp0 (order_by, "file_count") == 0) else if (g_strcmp0 (order_by, "file_count") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY f.file_count DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY f.file_count DESC, i.repo_id");
else else
snprintf (sql, sizeof(sql), "%sORDER BY i.update_time DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY i.update_time DESC, i.repo_id");
break; break;
case SEAF_DB_TYPE_SQLITE: case SEAF_DB_TYPE_SQLITE:
sql_base= "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, " g_string_append (sql, "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
"i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM " "i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM "
"RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id " "RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id "
"LEFT JOIN Branch b ON i.repo_id = b.repo_id " "LEFT JOIN Branch b ON i.repo_id = b.repo_id "
"LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id " "LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id " "LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id " "LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND " "WHERE r.repo_id IS NOT NULL ");
"v.repo_id IS NULL "; if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
if (g_strcmp0 (order_by, "size") == 0) if (g_strcmp0 (order_by, "size") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY s.size DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY s.size DESC, i.repo_id");
else if (g_strcmp0 (order_by, "file_count") == 0) else if (g_strcmp0 (order_by, "file_count") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY f.file_count DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY f.file_count DESC, i.repo_id");
else else
snprintf (sql, sizeof(sql), "%sORDER BY i.update_time DESC, i.repo_id", sql_base); g_string_append_printf (sql, "ORDER BY i.update_time DESC, i.repo_id");
break; break;
default: default:
g_string_free (sql, TRUE);
return NULL; return NULL;
} }
rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql, rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql->str,
collect_repos_fill_size_commit, &ret, collect_repos_fill_size_commit, &ret,
0); 0);
} else { } else {
switch (seaf_db_type(mgr->seaf->db)) { switch (seaf_db_type(mgr->seaf->db)) {
case SEAF_DB_TYPE_MYSQL: case SEAF_DB_TYPE_MYSQL:
sql_base = "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, " g_string_append (sql, "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
"i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM " "i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM "
"RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id " "RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id "
"LEFT JOIN Branch b ON i.repo_id = b.repo_id " "LEFT JOIN Branch b ON i.repo_id = b.repo_id "
"LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id " "LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id " "LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id " "LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND " "WHERE r.repo_id IS NOT NULL ");
"v.repo_id IS NULL "; if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
if (g_strcmp0 (order_by, "size") == 0) if (g_strcmp0 (order_by, "size") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY s.size DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY s.size DESC, i.repo_id LIMIT ? OFFSET ?");
else if (g_strcmp0 (order_by, "file_count") == 0) else if (g_strcmp0 (order_by, "file_count") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY f.file_count DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY f.file_count DESC, i.repo_id LIMIT ? OFFSET ?");
else else
snprintf (sql, sizeof(sql), "%sORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?");
break; break;
case SEAF_DB_TYPE_SQLITE: case SEAF_DB_TYPE_SQLITE:
sql_base = "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, " g_string_append (sql, "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
"i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM " "i.version, i.is_encrypted, i.last_modifier, i.status, f.file_count FROM "
"RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id " "RepoInfo i LEFT JOIN RepoSize s ON i.repo_id = s.repo_id "
"LEFT JOIN Branch b ON i.repo_id = b.repo_id " "LEFT JOIN Branch b ON i.repo_id = b.repo_id "
"LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id " "LEFT JOIN RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id " "LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id " "LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND " "WHERE r.repo_id IS NOT NULL ");
"v.repo_id IS NULL "; if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
if (g_strcmp0 (order_by, "size") == 0) if (g_strcmp0 (order_by, "size") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY s.size DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY s.size DESC, i.repo_id LIMIT ? OFFSET ?");
else if (g_strcmp0 (order_by, "file_count") == 0) else if (g_strcmp0 (order_by, "file_count") == 0)
snprintf (sql, sizeof(sql), "%sORDER BY f.file_count DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY f.file_count DESC, i.repo_id LIMIT ? OFFSET ?");
else else
snprintf (sql, sizeof(sql), "%sORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?", sql_base); g_string_append_printf (sql, "ORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?");
break; break;
default: default:
g_string_free (sql, TRUE);
return NULL; return NULL;
} }
rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql, rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql->str,
collect_repos_fill_size_commit, &ret, collect_repos_fill_size_commit, &ret,
2, "int", limit, "int", start); 2, "int", limit, "int", start);
} }
g_string_free (sql, TRUE);
if (rc < 0) if (rc < 0)
return NULL; return NULL;

View File

@ -147,7 +147,7 @@ seaf_repo_manager_repo_exists (SeafRepoManager *manager, const gchar *id);
GList* GList*
seaf_repo_manager_get_repo_list (SeafRepoManager *mgr, int start, int limit, seaf_repo_manager_get_repo_list (SeafRepoManager *mgr, int start, int limit,
const gchar *order_by); const gchar *order_by, int ret_virt_repo);
gint64 gint64
seaf_repo_manager_count_repos (SeafRepoManager *mgr, GError **error); seaf_repo_manager_count_repos (SeafRepoManager *mgr, GError **error);

View File

@ -91,7 +91,7 @@ static void start_rpc_service (const char *seafile_dir,
searpc_server_register_function ("seafserv-threaded-rpcserver", searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_repo_list, seafile_get_repo_list,
"seafile_get_repo_list", "seafile_get_repo_list",
searpc_signature_objlist__int_int_string()); searpc_signature_objlist__int_int_string_int());
searpc_server_register_function ("seafserv-threaded-rpcserver", searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_count_repos, seafile_count_repos,
"seafile_count_repos", "seafile_count_repos",