mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-25 06:25:13 +00:00
Merge pull request #296 from haiwen/fix_get_repo_list
seaf_repo_manager_get_repo_list should get all the repos in a loop
This commit is contained in:
@@ -2420,73 +2420,90 @@ seaf_repo_manager_get_repo_id_list (SeafRepoManager *mgr)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct FileCount {
|
|
||||||
char *repo_id;
|
|
||||||
gint64 file_count;
|
|
||||||
} FileCount;
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_file_count (gpointer data)
|
|
||||||
{
|
|
||||||
if (!data)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FileCount *file_count = data;
|
|
||||||
g_free (file_count->repo_id);
|
|
||||||
g_free (file_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
get_file_count_cb (SeafDBRow *row, void *data)
|
|
||||||
{
|
|
||||||
GList **file_counts = data;
|
|
||||||
const char *repo_id = seaf_db_row_get_column_text (row, 0);
|
|
||||||
gint64 fcount = seaf_db_row_get_column_int64 (row, 1);
|
|
||||||
|
|
||||||
FileCount *file_count = g_new0 (FileCount, 1);
|
|
||||||
file_count->repo_id = g_strdup (repo_id);
|
|
||||||
file_count->file_count = fcount;
|
|
||||||
*file_counts = g_list_prepend (*file_counts, file_count);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
GList *file_counts = NULL, *ptr;
|
|
||||||
GList *ret = NULL;
|
GList *ret = NULL;
|
||||||
SeafRepo *repo;
|
char *sql = NULL;
|
||||||
FileCount *file_count;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (start == -1 && limit == -1)
|
if (start == -1 && limit == -1) {
|
||||||
rc = seaf_db_statement_foreach_row (mgr->seaf->db,
|
switch (seaf_db_type(mgr->seaf->db)) {
|
||||||
"SELECT r.repo_id, c.file_count FROM Repo r LEFT JOIN RepoFileCount c "
|
case SEAF_DB_TYPE_MYSQL:
|
||||||
"ON r.repo_id = c.repo_id",
|
sql = "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
|
||||||
get_file_count_cb, &file_counts,
|
"i.version, i.is_encrypted, i.last_modifier, i.status 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id";
|
||||||
|
break;
|
||||||
|
case SEAF_DB_TYPE_PGSQL:
|
||||||
|
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 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id";
|
||||||
|
break;
|
||||||
|
case SEAF_DB_TYPE_SQLITE:
|
||||||
|
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 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql,
|
||||||
|
collect_repos_fill_size_commit, &ret,
|
||||||
0);
|
0);
|
||||||
else
|
} else {
|
||||||
rc = seaf_db_statement_foreach_row (mgr->seaf->db,
|
switch (seaf_db_type(mgr->seaf->db)) {
|
||||||
"SELECT r.repo_id, c.file_count FROM Repo r LEFT JOIN RepoFileCount c "
|
case SEAF_DB_TYPE_MYSQL:
|
||||||
"ON r.repo_id = c.repo_id ORDER BY r.repo_id LIMIT ? OFFSET ?",
|
sql = "SELECT i.repo_id, s.size, b.commit_id, i.name, i.update_time, "
|
||||||
get_file_count_cb, &file_counts,
|
"i.version, i.is_encrypted, i.last_modifier, i.status 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?";
|
||||||
|
break;
|
||||||
|
case SEAF_DB_TYPE_PGSQL:
|
||||||
|
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 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?";
|
||||||
|
break;
|
||||||
|
case SEAF_DB_TYPE_SQLITE:
|
||||||
|
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 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 "
|
||||||
|
"WHERE i.repo_id IN (SELECT r.repo_id FROM Repo r) AND "
|
||||||
|
"i.repo_id NOT IN (SELECT v.repo_id FROM VirtualRepo v) "
|
||||||
|
"ORDER BY i.update_time DESC, i.repo_id LIMIT ? OFFSET ?";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = seaf_db_statement_foreach_row (mgr->seaf->db, sql,
|
||||||
|
collect_repos_fill_size_commit, &ret,
|
||||||
2, "int", limit, "int", start);
|
2, "int", limit, "int", start);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (ptr = file_counts; ptr; ptr = ptr->next) {
|
|
||||||
file_count = ptr->data;
|
|
||||||
repo = seaf_repo_manager_get_repo_ex (mgr, file_count->repo_id);
|
|
||||||
if (repo != NULL) {
|
|
||||||
repo->file_count = file_count->file_count;
|
|
||||||
ret = g_list_prepend (ret, repo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free_full (file_counts, free_file_count);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user