mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 21:35:04 +00:00
New function timeline_fn_by_md5().
This commit is contained in:
parent
819211c620
commit
b8cd0d6363
1 changed files with 26 additions and 12 deletions
38
data.c
38
data.c
|
@ -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,9 +1395,13 @@ 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);
|
||||||
|
|
||||||
qmsg = _enqueue_put(fn, qmsg);
|
/* if it's to be sent right now, bypass the disk queue and post the job */
|
||||||
|
if (retries == 0)
|
||||||
srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
|
job_post(qmsg);
|
||||||
|
else {
|
||||||
|
qmsg = _enqueue_put(fn, qmsg);
|
||||||
|
srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue