summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-24 08:09:57 +0100
committerdefault <nobody@localhost>2022-11-24 08:09:57 +0100
commitecea10e11c00ac6a27954d7e8ed595e92ba69031 (patch)
tree116877d038ae18b9fcb5d0addc4907c6bcfde9f0 /data.c
parent9d7b35940f2a09b2ef1a8e1e705821b362ebf7c9 (diff)
Function object_add() also update the parent's children index.
Diffstat (limited to 'data.c')
-rw-r--r--data.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/data.c b/data.c
index bc80b1b..f5bd131 100644
--- a/data.c
+++ b/data.c
@@ -193,7 +193,7 @@ double mtime(char *fn)
/** database 2.1+ **/
-int index_add(const char *fn, const char *md5)
+int index_add_md5(const char *fn, const char *md5)
/* adds an md5 to an index */
{
int status = 200;
@@ -212,6 +212,15 @@ int index_add(const char *fn, const char *md5)
}
+int index_add(const char *fn, const char *id)
+/* adds an id to an index */
+{
+ xs *md5 = xs_md5_hex(id, strlen(id));
+
+ return index_add_md5(fn, md5);
+}
+
+
int index_del(const char *fn, const char *md5)
/* deletes an md5 from an index */
{
@@ -386,6 +395,19 @@ int object_add(const char *id, d_char *obj)
fwrite(j, strlen(j), 1, f);
fclose(f);
+
+ /* does this object has a parent? */
+ char *in_reply_to = xs_dict_get(obj, "inReplyTo");
+
+ if (!xs_is_null(in_reply_to)) {
+ /* update the children index of the parent */
+ xs *pfn = _object_fn(in_reply_to);
+
+ if (mtime(pfn) > 0.0) {
+ pfn = xs_replace_i(pfn, ".json", "_c.idx");
+ index_add(pfn, id);
+ }
+ }
}
else
status = 500;