diff options
| author | 2022-11-24 08:09:57 +0100 | |
|---|---|---|
| committer | 2022-11-24 08:09:57 +0100 | |
| commit | ecea10e11c00ac6a27954d7e8ed595e92ba69031 (patch) | |
| tree | 116877d038ae18b9fcb5d0addc4907c6bcfde9f0 | |
| parent | Renamed listfile functions to index. (diff) | |
| download | snac2-ecea10e11c00ac6a27954d7e8ed595e92ba69031.tar.gz snac2-ecea10e11c00ac6a27954d7e8ed595e92ba69031.tar.xz snac2-ecea10e11c00ac6a27954d7e8ed595e92ba69031.zip | |
Function object_add() also update the parent's children index.
| -rw-r--r-- | data.c | 24 |
1 files changed, 23 insertions, 1 deletions
| @@ -193,7 +193,7 @@ double mtime(char *fn) | |||
| 193 | 193 | ||
| 194 | /** database 2.1+ **/ | 194 | /** database 2.1+ **/ |
| 195 | 195 | ||
| 196 | int index_add(const char *fn, const char *md5) | 196 | int index_add_md5(const char *fn, const char *md5) |
| 197 | /* adds an md5 to an index */ | 197 | /* adds an md5 to an index */ |
| 198 | { | 198 | { |
| 199 | int status = 200; | 199 | int status = 200; |
| @@ -212,6 +212,15 @@ int index_add(const char *fn, const char *md5) | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | 214 | ||
| 215 | int index_add(const char *fn, const char *id) | ||
| 216 | /* adds an id to an index */ | ||
| 217 | { | ||
| 218 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 219 | |||
| 220 | return index_add_md5(fn, md5); | ||
| 221 | } | ||
| 222 | |||
| 223 | |||
| 215 | int index_del(const char *fn, const char *md5) | 224 | int index_del(const char *fn, const char *md5) |
| 216 | /* deletes an md5 from an index */ | 225 | /* deletes an md5 from an index */ |
| 217 | { | 226 | { |
| @@ -386,6 +395,19 @@ int object_add(const char *id, d_char *obj) | |||
| 386 | 395 | ||
| 387 | fwrite(j, strlen(j), 1, f); | 396 | fwrite(j, strlen(j), 1, f); |
| 388 | fclose(f); | 397 | fclose(f); |
| 398 | |||
| 399 | /* does this object has a parent? */ | ||
| 400 | char *in_reply_to = xs_dict_get(obj, "inReplyTo"); | ||
| 401 | |||
| 402 | if (!xs_is_null(in_reply_to)) { | ||
| 403 | /* update the children index of the parent */ | ||
| 404 | xs *pfn = _object_fn(in_reply_to); | ||
| 405 | |||
| 406 | if (mtime(pfn) > 0.0) { | ||
| 407 | pfn = xs_replace_i(pfn, ".json", "_c.idx"); | ||
| 408 | index_add(pfn, id); | ||
| 409 | } | ||
| 410 | } | ||
| 389 | } | 411 | } |
| 390 | else | 412 | else |
| 391 | status = 500; | 413 | status = 500; |