Skip to content

Commit

Permalink
Get repo list add return virtual repos (#605)
Browse files Browse the repository at this point in the history
Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Mar 20, 2023
1 parent 6ca4f18 commit ad5ce70
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 40 deletions.
8 changes: 4 additions & 4 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ seafile_pop_event(const char *channel, GError **error)
#endif

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;

ret = convert_repo_list (repos);
Expand Down Expand Up @@ -565,7 +565,7 @@ seafile_unsync_repos_by_account (const char *server_addr, const char *email, GEr
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) {
return 0;
}
Expand Down Expand Up @@ -602,7 +602,7 @@ seafile_remove_repo_tokens_by_account (const char *server_addr, const char *emai
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) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion include/seafile-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ seafile_get_session_info (GError **error);
*
* 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
seafile_count_repos (GError **error);
Expand Down
1 change: 1 addition & 0 deletions lib/rpc_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
[ "objlist", ["int", "string"] ],
[ "objlist", ["int", "int", "int"] ],
[ "objlist", ["int", "int", "string"] ],
[ "objlist", ["int", "int", "string", "int"] ],
[ "objlist", ["string"] ],
[ "objlist", ["string", "int"] ],
[ "objlist", ["string", "int", "int"] ],
Expand Down
4 changes: 2 additions & 2 deletions python/seafile/rpcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def seafile_destroy_repo(repo_id):
pass
remove_repo = seafile_destroy_repo

@searpc_func("objlist", ["int", "int"])
def seafile_get_repo_list(start, limit, order_by):
@searpc_func("objlist", ["int", "int", "string", "int"])
def seafile_get_repo_list(start, limit, order_by, ret_virt_repo):
pass
get_repo_list = seafile_get_repo_list

Expand Down
4 changes: 2 additions & 2 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def get_repo(self, repo_id):
def remove_repo(self, 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 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):
return seafserv_threaded_rpc.count_repos()
Expand Down
65 changes: 36 additions & 29 deletions server/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2532,101 +2532,108 @@ seaf_repo_manager_get_repo_id_list (SeafRepoManager *mgr)
}

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;
char *sql_base = NULL;
char sql[512];
int rc;
GString *sql = g_string_new ("");

if (start == -1 && limit == -1) {
switch (seaf_db_type(mgr->seaf->db)) {
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 "
"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 RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND "
"v.repo_id IS NULL ";
"WHERE r.repo_id IS NOT NULL ");
if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
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)
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
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;
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 "
"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 RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND "
"v.repo_id IS NULL ";
"WHERE r.repo_id IS NOT NULL ");
if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
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)
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
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;
default:
g_string_free (sql, TRUE);
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,
0);
} else {
switch (seaf_db_type(mgr->seaf->db)) {
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 "
"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 RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND "
"v.repo_id IS NULL ";
"WHERE r.repo_id IS NOT NULL ");
if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
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)
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
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;
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 "
"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 RepoFileCount f ON i.repo_id = f.repo_id "
"LEFT JOIN Repo r ON i.repo_id = r.repo_id "
"LEFT JOIN VirtualRepo v ON i.repo_id = v.repo_id "
"WHERE r.repo_id IS NOT NULL AND "
"v.repo_id IS NULL ";
"WHERE r.repo_id IS NOT NULL ");
if (!ret_virt_repo)
g_string_append_printf (sql, "AND v.repo_id IS NULL ");
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)
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
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;
default:
g_string_free (sql, TRUE);
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,
2, "int", limit, "int", start);
}

g_string_free (sql, TRUE);

if (rc < 0)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion server/repo-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ seaf_repo_manager_repo_exists (SeafRepoManager *manager, const gchar *id);

GList*
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
seaf_repo_manager_count_repos (SeafRepoManager *mgr, GError **error);
Expand Down
2 changes: 1 addition & 1 deletion server/seaf-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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_string());
searpc_signature_objlist__int_int_string_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_count_repos,
"seafile_count_repos",
Expand Down

0 comments on commit ad5ce70

Please sign in to comment.