From: Olaf Wintermann Date: Mon, 4 Aug 2025 19:25:36 +0000 (+0200) Subject: add note_store_count_repository_usage_async X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=920c3e2773c23738f968f18887de7861c6777af8;p=note.git add note_store_count_repository_usage_async --- diff --git a/application/store.c b/application/store.c index eb43cb7..ee52203 100644 --- a/application/store.c +++ b/application/store.c @@ -136,6 +136,9 @@ " local_path = ? " \ "where repository_id = ?;" +#define SQL_REPOSITORY_USAGE \ + "select count(*) from notebooks where repository_id = ?;" + static DBUConnection *connection; static UiThreadpool *queue; @@ -1095,3 +1098,41 @@ void note_store_save_repository_async(UiObject *obj, Repository *repository, exe job->error = 0; ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_store_save_repository, job, (ui_callback)uithr_save_repository_job_finished, job); } + + +typedef struct CountJob { + countresult_func resultcb; + void *userdata; + int64_t id1; + int64_t id2; + int64_t num; +} CountJob; + +static void uithr_countjob_finished(UiEvent *event, CountJob *job) { + job->resultcb(event, job->num, job->userdata); + free(job); +} + +static int qthr_count_repo_usage(CountJob *job) { + DBUQuery *q = connection->createQuery(connection, NULL); + dbuQuerySetSQL(q, SQL_REPOSITORY_USAGE); + dbuQuerySetParamInt64(q, 1, job->id1); + if(!dbuQueryExec(q)) { + DBUResult *result = dbuQueryGetResult(q); + if(result) { + dbuResultAsInt64(result, &job->num); + } + } + dbuQueryFree(q); + return 0; +} + +void note_store_count_repository_usage_async(UiObject *obj, Repository *repository, countresult_func resultcb, void *userdata) { + CountJob *job = malloc(sizeof(CountJob)); + job->resultcb = resultcb; + job->userdata = userdata; + job->id1 = repository->repository_id; + job->id2 = 0; + job->num = -1; + ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_count_repo_usage, job, (ui_callback)uithr_countjob_finished, job); +} diff --git a/application/store.h b/application/store.h index 466a502..71ae9c7 100644 --- a/application/store.h +++ b/application/store.h @@ -58,6 +58,7 @@ typedef void (*stringresult_func)(UiEvent *event, cxmutstr result, void *userdat typedef void (*execresult_func)(UiEvent *event, int error, void *userdata); typedef void (*createresult_func)(UiEvent *event, int64_t newid, int error, void *userdata); +typedef void (*countresult_func)(UiEvent *event, int64_t n, void *userdata); int init_note_store(); @@ -123,6 +124,8 @@ void note_store_notebook_swap_position_async( void note_store_save_repository_async(UiObject *obj, Repository *repository, execresult_func resultcb, void *userdata); +void note_store_count_repository_usage_async(UiObject *obj, Repository *repository, countresult_func resultcb, void *userdata); + #ifdef __cplusplus } #endif