summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2023-02-08 13:06:49 +0100
committerGravatar default2023-02-08 13:06:49 +0100
commitb8cd0d636325c5c648d199c651903feae411d497 (patch)
tree4eb968013612c6ef5fe1ec58e0fe816ee3f68651 /data.c
parentUpdated TODO. (diff)
downloadsnac2-b8cd0d636325c5c648d199c651903feae411d497.tar.gz
snac2-b8cd0d636325c5c648d199c651903feae411d497.tar.xz
snac2-b8cd0d636325c5c648d199c651903feae411d497.zip
New function timeline_fn_by_md5().
Diffstat (limited to 'data.c')
-rw-r--r--data.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/data.c b/data.c
index ac429fa..6e12523 100644
--- a/data.c
+++ b/data.c
@@ -810,22 +810,32 @@ double timeline_mtime(snac *snac)
810} 810}
811 811
812 812
813xs_str *timeline_fn_by_md5(snac *snac, const char *md5)
814/* get the filename of an entry by md5 from any timeline */
815{
816 xs_str *fn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
817
818 if (mtime(fn) == 0.0) {
819 fn = xs_free(fn);
820 fn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
821
822 if (mtime(fn) == 0.0)
823 fn = xs_free(fn);
824 }
825
826 return fn;
827}
828
829
813int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) 830int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
814/* gets a message from the timeline */ 831/* gets a message from the timeline */
815{ 832{
816 int status = 404; 833 int status = 404;
817 FILE *f = NULL; 834 FILE *f = NULL;
818 835
819 /* try to open from the private cache first */ 836 xs *fn = timeline_fn_by_md5(snac, md5);
820 xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
821
822 if ((f = fopen(prfn, "r")) == NULL) {
823 /* try now the public one */
824 xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
825 f = fopen(pufn, "r");
826 }
827 837
828 if (f != NULL) { 838 if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
829 flock(fileno(f), LOCK_SH); 839 flock(fileno(f), LOCK_SH);
830 840
831 xs *j = xs_readall(f); 841 xs *j = xs_readall(f);
@@ -1385,9 +1395,13 @@ void enqueue_output_raw(const char *keyid, const char *seckey,
1385 qmsg = xs_dict_append(qmsg, "keyid", keyid); 1395 qmsg = xs_dict_append(qmsg, "keyid", keyid);
1386 qmsg = xs_dict_append(qmsg, "seckey", seckey); 1396 qmsg = xs_dict_append(qmsg, "seckey", seckey);
1387 1397
1388 qmsg = _enqueue_put(fn, qmsg); 1398 /* if it's to be sent right now, bypass the disk queue and post the job */
1389 1399 if (retries == 0)
1390 srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries)); 1400 job_post(qmsg);
1401 else {
1402 qmsg = _enqueue_put(fn, qmsg);
1403 srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
1404 }
1391} 1405}
1392 1406
1393 1407