diff options
| author | 2024-03-12 17:54:54 +0100 | |
|---|---|---|
| committer | 2024-03-12 17:54:54 +0100 | |
| commit | f485dbdaf0f6372b9815be3d78ae2839e80d6946 (patch) | |
| tree | b7ddb23b52f9a199fd38f85168f46119fb4ff757 /data.c | |
| parent | Updated documentation. (diff) | |
| download | snac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.tar.gz snac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.tar.xz snac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.zip | |
Added actor refreshing via the user queue.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 47 |
1 files changed, 41 insertions, 6 deletions
| @@ -797,6 +797,20 @@ double object_ctime(const char *id) | |||
| 797 | } | 797 | } |
| 798 | 798 | ||
| 799 | 799 | ||
| 800 | double object_mtime_by_md5(const char *md5) | ||
| 801 | { | ||
| 802 | xs *fn = _object_fn_by_md5(md5, "object_mtime_by_md5"); | ||
| 803 | return mtime(fn); | ||
| 804 | } | ||
| 805 | |||
| 806 | |||
| 807 | double object_mtime(const char *id) | ||
| 808 | { | ||
| 809 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 810 | return object_mtime_by_md5(md5); | ||
| 811 | } | ||
| 812 | |||
| 813 | |||
| 800 | xs_str *_object_index_fn(const char *id, const char *idxsfx) | 814 | xs_str *_object_index_fn(const char *id, const char *idxsfx) |
| 801 | /* returns the filename of an object's index */ | 815 | /* returns the filename of an object's index */ |
| 802 | { | 816 | { |
| @@ -1552,7 +1566,6 @@ int actor_get(const char *actor, xs_dict **data) | |||
| 1552 | else | 1566 | else |
| 1553 | d = xs_free(d); | 1567 | d = xs_free(d); |
| 1554 | 1568 | ||
| 1555 | #ifdef STALE_ACTORS | ||
| 1556 | xs *fn = _object_fn(actor); | 1569 | xs *fn = _object_fn(actor); |
| 1557 | double max_time; | 1570 | double max_time; |
| 1558 | 1571 | ||
| @@ -1561,13 +1574,20 @@ int actor_get(const char *actor, xs_dict **data) | |||
| 1561 | 1574 | ||
| 1562 | if (mtime(fn) + max_time < (double) time(NULL)) { | 1575 | if (mtime(fn) + max_time < (double) time(NULL)) { |
| 1563 | /* actor data exists but also stinks */ | 1576 | /* actor data exists but also stinks */ |
| 1564 | |||
| 1565 | /* touch the file */ | ||
| 1566 | utimes(fn, NULL); | ||
| 1567 | |||
| 1568 | status = 205; /* "205: Reset Content" "110: Response Is Stale" */ | 1577 | status = 205; /* "205: Reset Content" "110: Response Is Stale" */ |
| 1569 | } | 1578 | } |
| 1570 | #endif /* STALE_ACTORS */ | 1579 | |
| 1580 | return status; | ||
| 1581 | } | ||
| 1582 | |||
| 1583 | |||
| 1584 | int actor_get_refresh(snac *user, const char *actor, xs_dict **data) | ||
| 1585 | /* gets an actor and requests and refresh if it's stale */ | ||
| 1586 | { | ||
| 1587 | int status = actor_get(actor, data); | ||
| 1588 | |||
| 1589 | if (status == 205) | ||
| 1590 | enqueue_actor_request(user, actor); | ||
| 1571 | 1591 | ||
| 1572 | return status; | 1592 | return status; |
| 1573 | } | 1593 | } |
| @@ -2429,6 +2449,21 @@ void enqueue_verify_links(snac *user) | |||
| 2429 | } | 2449 | } |
| 2430 | 2450 | ||
| 2431 | 2451 | ||
| 2452 | void enqueue_actor_request(snac *user, const char *actor) | ||
| 2453 | /* enqueues an actor request */ | ||
| 2454 | { | ||
| 2455 | xs *qmsg = _new_qmsg("actor_request", "", 0); | ||
| 2456 | char *ntid = xs_dict_get(qmsg, "ntid"); | ||
| 2457 | xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); | ||
| 2458 | |||
| 2459 | qmsg = xs_dict_append(qmsg, "actor", actor); | ||
| 2460 | |||
| 2461 | qmsg = _enqueue_put(fn, qmsg); | ||
| 2462 | |||
| 2463 | snac_debug(user, 1, xs_fmt("enqueue_actor_request %s", user->actor)); | ||
| 2464 | } | ||
| 2465 | |||
| 2466 | |||
| 2432 | void enqueue_request_replies(snac *user, const char *id) | 2467 | void enqueue_request_replies(snac *user, const char *id) |
| 2433 | /* enqueues a request for the replies of a message */ | 2468 | /* enqueues a request for the replies of a message */ |
| 2434 | { | 2469 | { |