]> uap-core.de Git - note.git/commitdiff
get infos from notebooks table when loading the notebook tree structure
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 20 May 2025 18:59:47 +0000 (20:59 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 20 May 2025 18:59:47 +0000 (20:59 +0200)
application/store.c
application/types.h

index 1bef075b4be082d713afff6f5ad5e985c5795575..7a271797d9f34fd77fc495c52256d5da49b8e956 100644 (file)
@@ -53,7 +53,8 @@
     "    inner join cols p on c.parent_id = p.resource_id and c.iscollection = 1 \n" \
     "    where p.depth < 3\n" \
     ")\n" \
-    "select * from cols\n" \
+    "select n.*, r.resource_id as [__resources__resource_id], r.* from cols r\n" \
+    "left join notebooks n on r.resource_id = n.resource_id\n" \
     "order by path;"
 
 #define SQL_NOTEBOOK_GET_NOTES \
@@ -327,7 +328,7 @@ void note_store_reload() {
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTEBOOK_STRUCTURE);
     dbuQuerySetParamInt64(q, 1, settings_default_node_id);
-    DBUObjectBuilder *builder = dbuObjectBuilder(resource_class, q, mp->allocator);
+    DBUObjectBuilder *builder = dbuObjectBuilder(notebook_class, q, mp->allocator);
     CxList *collections = dbuObjectBuilderGetList(builder);
     dbuObjectBuilderDestroy(builder);
     
@@ -343,12 +344,18 @@ void note_store_reload() {
     store->root = NULL;
     store->trash = NULL;
     
-    // key: collection_id  value: Collection*
+    // key: resource_id  value: Notebook*
     CxMap *collection_map = cxHashMapCreate(NULL, CX_STORE_POINTERS, cxListSize(collections) + 16);
     
     // convert result list to tree
     CxIterator i = cxListIterator(collections);
-    cx_foreach(Resource *, col, i) {
+    cx_foreach(Notebook *, nb, i) {
+        // switch link between resource and notebook
+        Resource *col = nb->resource;
+        if(!col) {
+            continue; // error, should not happen
+        }
+        col->notebook = nb;
         CxHashKey key = cx_hash_key(&col->resource_id, sizeof(int64_t));
         cxMapPut(collection_map, key, col);
         if(i.index == 0) {
index c83f6d01bcb99bbeccb6cce8c08869b115365588..5e2a9b0fa9b4b180e61187218af65313af3b72da 100644 (file)
@@ -93,6 +93,8 @@ struct Resource {
      */
     CxList     *attachments;
     
+    Notebook   *notebook;
+    
     /*
      * indicates, whether content or bin_content was queried
      * content_loaded is not a column in the Notes table, however it can be