Added actor refreshing via the user queue.

This commit is contained in:
default 2024-03-12 17:54:54 +01:00
parent 3a1d531d92
commit f485dbdaf0
5 changed files with 63 additions and 8 deletions

View file

@ -2244,6 +2244,22 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
if (strcmp(type, "verify_links") == 0) { if (strcmp(type, "verify_links") == 0) {
verify_links(snac); verify_links(snac);
} }
else
if (strcmp(type, "actor_request") == 0) {
const char *actor = xs_dict_get(q_item, "actor");
double mtime = object_mtime(actor);
double max_time = 3600.0 * 36.0;
if (mtime + max_time < (double) time(NULL)) {
xs *actor_o = NULL;
int status;
if (valid_status((status = activitypub_request(snac, actor, &actor_o))))
actor_add(actor, actor_o);
snac_log(snac, xs_fmt("refresh actor %s %d", actor, status));
}
}
else else
snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type)); snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type));
} }

47
data.c
View file

@ -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) xs_str *_object_index_fn(const char *id, const char *idxsfx)
/* returns the filename of an object's index */ /* returns the filename of an object's index */
{ {
@ -1552,7 +1566,6 @@ int actor_get(const char *actor, xs_dict **data)
else else
d = xs_free(d); d = xs_free(d);
#ifdef STALE_ACTORS
xs *fn = _object_fn(actor); xs *fn = _object_fn(actor);
double max_time; double max_time;
@ -1561,13 +1574,20 @@ int actor_get(const char *actor, xs_dict **data)
if (mtime(fn) + max_time < (double) time(NULL)) { if (mtime(fn) + max_time < (double) time(NULL)) {
/* actor data exists but also stinks */ /* actor data exists but also stinks */
/* touch the file */
utimes(fn, NULL);
status = 205; /* "205: Reset Content" "110: Response Is Stale" */ 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; 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) void enqueue_request_replies(snac *user, const char *id)
/* enqueues a request for the replies of a message */ /* enqueues a request for the replies of a message */
{ {

2
html.c
View file

@ -245,7 +245,7 @@ xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
xs *actor = NULL; xs *actor = NULL;
xs_html *actor_icon = NULL; xs_html *actor_icon = NULL;
if (actor_id && valid_status(actor_get(actor_id, &actor))) { if (actor_id && valid_status(actor_get_refresh(user, actor_id, &actor))) {
char *date = NULL; char *date = NULL;
char *udate = NULL; char *udate = NULL;
char *url = NULL; char *url = NULL;

View file

@ -746,7 +746,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
/* converts an ActivityPub note to a Mastodon status */ /* converts an ActivityPub note to a Mastodon status */
{ {
xs *actor = NULL; xs *actor = NULL;
actor_get(get_atto(msg), &actor); actor_get_refresh(snac, get_atto(msg), &actor);
/* if the author is not here, discard */ /* if the author is not here, discard */
if (actor == NULL) if (actor == NULL)

4
snac.h
View file

@ -110,6 +110,8 @@ int object_del(const char *id);
int object_del_if_unref(const char *id); int object_del_if_unref(const char *id);
double object_ctime_by_md5(const char *md5); double object_ctime_by_md5(const char *md5);
double object_ctime(const char *id); double object_ctime(const char *id);
double object_mtime_by_md5(const char *md5);
double object_mtime(const char *id);
int object_admire(const char *id, const char *actor, int like); int object_admire(const char *id, const char *actor, int like);
int object_unadmire(const char *id, const char *actor, int like); int object_unadmire(const char *id, const char *actor, int like);
@ -172,6 +174,7 @@ xs_list *tag_search(char *tag, int skip, int show);
int actor_add(const char *actor, xs_dict *msg); int actor_add(const char *actor, xs_dict *msg);
int actor_get(const char *actor, xs_dict **data); int actor_get(const char *actor, xs_dict **data);
int actor_get_refresh(snac *user, const char *actor, xs_dict **data);
int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag); int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
void static_put(snac *snac, const char *id, const char *data, int size); void static_put(snac *snac, const char *id, const char *data, int size);
@ -218,6 +221,7 @@ void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_t
void enqueue_message(snac *snac, const xs_dict *msg); void enqueue_message(snac *snac, const xs_dict *msg);
void enqueue_close_question(snac *user, const char *id, int end_secs); void enqueue_close_question(snac *user, const char *id, int end_secs);
void enqueue_verify_links(snac *user); void enqueue_verify_links(snac *user);
void enqueue_actor_request(snac *user, const char *actor);
void enqueue_request_replies(snac *user, const char *id); void enqueue_request_replies(snac *user, const char *id);
int was_question_voted(snac *user, const char *id); int was_question_voted(snac *user, const char *id);