commit 281f934
default
·
2024-05-14 03:17:33 +0000 UTC
parent ba00443
content_search() also searches the instance timeline.
M
data.c
+33,
-46
1@@ -2508,73 +2508,56 @@ xs_list *content_search(snac *user, const char *regex,
2 time_t t = time(NULL) + max_secs;
3 *timeout = 0;
4
5- /* iterate both timelines simultaneously */
6- xs *pub_tl = timeline_simple_list(user, "public", 0, XS_ALL);
7- int pub_c = 0;
8- char *pub_md5 = NULL;
9+ /* iterate all timelines simultaneously */
10+ xs_list *tls[3] = {0};
11+ char *md5s[3] = {0};
12+ int c[3] = {0};
13
14- xs *priv_tl = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new();
15- int priv_c = 0;
16- char *priv_md5 = NULL;
17+ tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */
18+ tls[1] = timeline_instance_list(0, XS_ALL); /* instance */
19+ tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new(); /* private or none */
20
21 /* first positioning */
22- xs_list_next(pub_tl, &pub_md5, &pub_c);
23- xs_list_next(priv_tl, &priv_md5, &priv_c);
24+ for (int n = 0; n < 3; n++)
25+ xs_list_next(tls[n], &md5s[n], &c[n]);
26
27 show += skip;
28
29 while (show > 0) {
30- char *md5 = NULL;
31- enum { NONE, PUBLIC, PRIVATE } from = NONE;
32-
33 /* timeout? */
34 if (time(NULL) > t) {
35 *timeout = 1;
36 break;
37 }
38
39- if (pub_md5 == NULL) {
40- /* out of both lists? done */
41- if (priv_md5 == NULL)
42- break;
43-
44- /* out of public: take element from the private timeline and advance */
45- from = PRIVATE;
46- }
47- else
48- if (priv_md5 == NULL) {
49- /* out of private: take element from the public timeline and advance */
50- from = PUBLIC;
51- }
52- else {
53- /* candidates from both: choose one from the file dates */
54- xs *pub_fn = xs_fmt("%s/public/%s.json", user->basedir, pub_md5);
55- xs *priv_fn = xs_fmt("%s/private/%s.json", user->basedir, priv_md5);
56+ /* find the newest post */
57+ int newest = -1;
58+ double mtime = 0.0;
59
60- if (mtime(pub_fn) < mtime(priv_fn))
61- from = PRIVATE;
62- else
63- from = PUBLIC;
64- }
65+ for (int n = 0; n < 3; n++) {
66+ if (md5s[n] != NULL) {
67+ xs *fn = _object_fn_by_md5(md5s[n], "content_search");
68+ double mt = mtime(fn);
69
70- if (from == PUBLIC) { /* public */
71- md5 = pub_md5;
72- if (!xs_list_next(pub_tl, &pub_md5, &pub_c))
73- pub_md5 = NULL;
74- }
75- else
76- if (from == PRIVATE) { /* private */
77- md5 = priv_md5;
78- if (!xs_list_next(priv_tl, &priv_md5, &priv_c))
79- priv_md5 = NULL;
80+ if (mt > mtime) {
81+ newest = n;
82+ mtime = mt;
83+ }
84+ }
85 }
86
87- if (md5 == NULL)
88+ if (newest == -1)
89 break;
90
91+ char *md5 = md5s[newest];
92+
93+ /* advance the chosen timeline */
94+ if (!xs_list_next(tls[newest], &md5s[newest], &c[newest]))
95+ md5s[newest] = NULL;
96+
97 xs *post = NULL;
98
99- if (!valid_status(timeline_get_by_md5(user, md5, &post)))
100+ if (!valid_status(object_get_by_md5(md5, &post)))
101 continue;
102
103 if (!xs_match(xs_dict_get_def(post, "type", "-"), POSTLIKE_OBJECT_TYPE))
104@@ -2608,6 +2591,10 @@ xs_list *content_search(snac *user, const char *regex,
105 }
106 }
107
108+ xs_free(tls[0]);
109+ xs_free(tls[1]);
110+ xs_free(tls[2]);
111+
112 return r;
113 }
114
M
html.c
+1,
-1
1@@ -2604,7 +2604,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2 else
3 title = xs_fmt(L("Nothing found for '%s'"), q);
4
5- *body = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 1);
6+ *body = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 0);
7 *b_size = strlen(*body);
8 status = 200;
9 }