diff --git a/common/rpc-service.c b/common/rpc-service.c index d9938770..741964e4 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -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); @@ -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; } @@ -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; } diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index 18943e46..c9717b62 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -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); diff --git a/lib/rpc_table.py b/lib/rpc_table.py index 1a93f64d..e10bb2f7 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -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"] ], diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 4747b1e3..6559c2dd 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -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 diff --git a/python/seaserv/api.py b/python/seaserv/api.py index 6985f9cc..ece5270c 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -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() diff --git a/server/repo-mgr.c b/server/repo-mgr.c index 7c7aab46..84d4fe61 100644 --- a/server/repo-mgr.c +++ b/server/repo-mgr.c @@ -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; diff --git a/server/repo-mgr.h b/server/repo-mgr.h index de79f8fc..0be20faf 100644 --- a/server/repo-mgr.h +++ b/server/repo-mgr.h @@ -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); diff --git a/server/seaf-server.c b/server/seaf-server.c index 7b6ef33e..acef0312 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -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",