commit b8cd0d6

default  ·  2023-02-08 12:06:49 +0000 UTC
parent 819211c
New function timeline_fn_by_md5().
1 files changed,  +26, -12
M data.c
M data.c
+26, -12
 1@@ -810,22 +810,32 @@ double timeline_mtime(snac *snac)
 2 }
 3 
 4 
 5+xs_str *timeline_fn_by_md5(snac *snac, const char *md5)
 6+/* get the filename of an entry by md5 from any timeline */
 7+{
 8+    xs_str *fn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
 9+
10+    if (mtime(fn) == 0.0) {
11+        fn = xs_free(fn);
12+        fn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
13+
14+        if (mtime(fn) == 0.0)
15+            fn = xs_free(fn);
16+    }
17+
18+    return fn;
19+}
20+
21+
22 int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
23 /* gets a message from the timeline */
24 {
25     int status = 404;
26     FILE *f    = NULL;
27 
28-    /* try to open from the private cache first */
29-    xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
30-
31-    if ((f = fopen(prfn, "r")) == NULL) {
32-        /* try now the public one */
33-        xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
34-        f = fopen(pufn, "r");
35-    }
36+    xs *fn = timeline_fn_by_md5(snac, md5);
37 
38-    if (f != NULL) {
39+    if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
40         flock(fileno(f), LOCK_SH);
41 
42         xs *j = xs_readall(f);
43@@ -1385,9 +1395,13 @@ void enqueue_output_raw(const char *keyid, const char *seckey,
44     qmsg = xs_dict_append(qmsg, "keyid",  keyid);
45     qmsg = xs_dict_append(qmsg, "seckey", seckey);
46 
47-    qmsg = _enqueue_put(fn, qmsg);
48-
49-    srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
50+    /* if it's to be sent right now, bypass the disk queue and post the job */
51+    if (retries == 0)
52+        job_post(qmsg);
53+    else {
54+        qmsg = _enqueue_put(fn, qmsg);
55+        srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
56+    }
57 }
58 
59