summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-10-02 17:52:40 +0200
committerdefault <nobody@localhost>2022-10-02 17:52:40 +0200
commit20fd70c01145e6be40edf231781497a2b5ec404f (patch)
treea78f5581853015cce7ffa9b8f4a2e43f96f5a772 /html.c
parentd29c00bd8f35c41a8cd9826d3353e1768da4e670 (diff)
Implemented local timeline cache.
Diffstat (limited to 'html.c')
-rw-r--r--html.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/html.c b/html.c
index 2a0b2a8..ad867af 100644
--- a/html.c
+++ b/html.c
@@ -8,6 +8,7 @@
#include "xs_regex.h"
#include "xs_set.h"
#include "xs_openssl.h"
+#include "xs_time.h"
#include "snac.h"
@@ -753,11 +754,24 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
if (p_path == NULL) {
/* public timeline */
- xs *list = local_list(&snac, 0xfffffff);
+ xs *h = xs_str_localtime(0, "%Y-%m.html");
- *body = html_timeline(&snac, list, 1);
- *b_size = strlen(*body);
- status = 200;
+ if (history_mtime(&snac, h) > timeline_mtime(&snac)) {
+ snac_debug(&snac, 1, xs_fmt("serving cached local timeline"));
+
+ *body = history_get(&snac, h);
+ *b_size = strlen(*body);
+ status = 200;
+ }
+ else {
+ xs *list = local_list(&snac, 0xfffffff);
+
+ *body = html_timeline(&snac, list, 1);
+ *b_size = strlen(*body);
+ status = 200;
+
+ history_add(&snac, h, *body, *b_size);
+ }
}
else
if (strcmp(p_path, "admin") == 0) {