summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-03-12 17:54:54 +0100
committerdefault <nobody@localhost>2024-03-12 17:54:54 +0100
commitf485dbdaf0f6372b9815be3d78ae2839e80d6946 (patch)
treeb7ddb23b52f9a199fd38f85168f46119fb4ff757 /data.c
parent3a1d531d92bb2e2b324468284d2f98175a579387 (diff)
Added actor refreshing via the user queue.
Diffstat (limited to 'data.c')
-rw-r--r--data.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/data.c b/data.c
index 44ce628..77d81d5 100644
--- a/data.c
+++ b/data.c
@@ -797,6 +797,20 @@ double object_ctime(const char *id)
}
+double object_mtime_by_md5(const char *md5)
+{
+ xs *fn = _object_fn_by_md5(md5, "object_mtime_by_md5");
+ return mtime(fn);
+}
+
+
+double object_mtime(const char *id)
+{
+ xs *md5 = xs_md5_hex(id, strlen(id));
+ return object_mtime_by_md5(md5);
+}
+
+
xs_str *_object_index_fn(const char *id, const char *idxsfx)
/* returns the filename of an object's index */
{
@@ -1552,7 +1566,6 @@ int actor_get(const char *actor, xs_dict **data)
else
d = xs_free(d);
-#ifdef STALE_ACTORS
xs *fn = _object_fn(actor);
double max_time;
@@ -1561,13 +1574,20 @@ int actor_get(const char *actor, xs_dict **data)
if (mtime(fn) + max_time < (double) time(NULL)) {
/* actor data exists but also stinks */
-
- /* touch the file */
- utimes(fn, NULL);
-
status = 205; /* "205: Reset Content" "110: Response Is Stale" */
}
-#endif /* STALE_ACTORS */
+
+ return status;
+}
+
+
+int actor_get_refresh(snac *user, const char *actor, xs_dict **data)
+/* gets an actor and requests and refresh if it's stale */
+{
+ int status = actor_get(actor, data);
+
+ if (status == 205)
+ enqueue_actor_request(user, actor);
return status;
}
@@ -2429,6 +2449,21 @@ void enqueue_verify_links(snac *user)
}
+void enqueue_actor_request(snac *user, const char *actor)
+/* enqueues an actor request */
+{
+ xs *qmsg = _new_qmsg("actor_request", "", 0);
+ char *ntid = xs_dict_get(qmsg, "ntid");
+ xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
+
+ qmsg = xs_dict_append(qmsg, "actor", actor);
+
+ qmsg = _enqueue_put(fn, qmsg);
+
+ snac_debug(user, 1, xs_fmt("enqueue_actor_request %s", user->actor));
+}
+
+
void enqueue_request_replies(snac *user, const char *id)
/* enqueues a request for the replies of a message */
{