commit ecea10e

default  ·  2022-11-24 07:09:57 +0000 UTC
parent 9d7b359
Function object_add() also update the parent's children index.
1 files changed,  +23, -1
M data.c
M data.c
+23, -1
 1@@ -193,7 +193,7 @@ double mtime(char *fn)
 2 
 3 /** database 2.1+ **/
 4 
 5-int index_add(const char *fn, const char *md5)
 6+int index_add_md5(const char *fn, const char *md5)
 7 /* adds an md5 to an index */
 8 {
 9     int status = 200;
10@@ -212,6 +212,15 @@ int index_add(const char *fn, const char *md5)
11 }
12 
13 
14+int index_add(const char *fn, const char *id)
15+/* adds an id to an index */
16+{
17+    xs *md5 = xs_md5_hex(id, strlen(id));
18+
19+    return index_add_md5(fn, md5);
20+}
21+
22+
23 int index_del(const char *fn, const char *md5)
24 /* deletes an md5 from an index */
25 {
26@@ -386,6 +395,19 @@ int object_add(const char *id, d_char *obj)
27 
28         fwrite(j, strlen(j), 1, f);
29         fclose(f);
30+
31+        /* does this object has a parent? */
32+        char *in_reply_to = xs_dict_get(obj, "inReplyTo");
33+
34+        if (!xs_is_null(in_reply_to)) {
35+            /* update the children index of the parent */
36+            xs *pfn = _object_fn(in_reply_to);
37+
38+            if (mtime(pfn) > 0.0) {
39+                pfn = xs_replace_i(pfn, ".json", "_c.idx");
40+                index_add(pfn, id);
41+            }
42+        }
43     }
44     else
45         status = 500;