New function timeline_fn_by_md5().

This commit is contained in:
default 2023-02-08 13:06:49 +01:00
parent 819211c620
commit b8cd0d6363

34
data.c
View file

@ -810,22 +810,32 @@ double timeline_mtime(snac *snac)
} }
xs_str *timeline_fn_by_md5(snac *snac, const char *md5)
/* get the filename of an entry by md5 from any timeline */
{
xs_str *fn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
if (mtime(fn) == 0.0) {
fn = xs_free(fn);
fn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
if (mtime(fn) == 0.0)
fn = xs_free(fn);
}
return fn;
}
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
/* gets a message from the timeline */ /* gets a message from the timeline */
{ {
int status = 404; int status = 404;
FILE *f = NULL; FILE *f = NULL;
/* try to open from the private cache first */ xs *fn = timeline_fn_by_md5(snac, md5);
xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
if ((f = fopen(prfn, "r")) == NULL) { if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
/* try now the public one */
xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
f = fopen(pufn, "r");
}
if (f != NULL) {
flock(fileno(f), LOCK_SH); flock(fileno(f), LOCK_SH);
xs *j = xs_readall(f); xs *j = xs_readall(f);
@ -1385,10 +1395,14 @@ void enqueue_output_raw(const char *keyid, const char *seckey,
qmsg = xs_dict_append(qmsg, "keyid", keyid); qmsg = xs_dict_append(qmsg, "keyid", keyid);
qmsg = xs_dict_append(qmsg, "seckey", seckey); qmsg = xs_dict_append(qmsg, "seckey", seckey);
/* if it's to be sent right now, bypass the disk queue and post the job */
if (retries == 0)
job_post(qmsg);
else {
qmsg = _enqueue_put(fn, qmsg); qmsg = _enqueue_put(fn, qmsg);
srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries)); srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
} }
}
void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries) void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries)