|
@@ -2508,73 +2508,56 @@ xs_list *content_search(snac *user, const char *regex,
|
|
|
time_t t = time(NULL) + max_secs;
|
|
|
*timeout = 0;
|
|
|
|
|
|
-
|
|
|
- xs *pub_tl = timeline_simple_list(user, "public", 0, XS_ALL);
|
|
|
- int pub_c = 0;
|
|
|
- char *pub_md5 = NULL;
|
|
|
+
|
|
|
+ xs_list *tls[3] = {0};
|
|
|
+ char *md5s[3] = {0};
|
|
|
+ int c[3] = {0};
|
|
|
|
|
|
- xs *priv_tl = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new();
|
|
|
- int priv_c = 0;
|
|
|
- char *priv_md5 = NULL;
|
|
|
+ tls[0] = timeline_simple_list(user, "public", 0, XS_ALL);
|
|
|
+ tls[1] = timeline_instance_list(0, XS_ALL);
|
|
|
+ tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new();
|
|
|
|
|
|
|
|
|
- xs_list_next(pub_tl, &pub_md5, &pub_c);
|
|
|
- xs_list_next(priv_tl, &priv_md5, &priv_c);
|
|
|
+ for (int n = 0; n < 3; n++)
|
|
|
+ xs_list_next(tls[n], &md5s[n], &c[n]);
|
|
|
|
|
|
show += skip;
|
|
|
|
|
|
while (show > 0) {
|
|
|
- char *md5 = NULL;
|
|
|
- enum { NONE, PUBLIC, PRIVATE } from = NONE;
|
|
|
-
|
|
|
|
|
|
if (time(NULL) > t) {
|
|
|
*timeout = 1;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (pub_md5 == NULL) {
|
|
|
-
|
|
|
- if (priv_md5 == NULL)
|
|
|
- break;
|
|
|
-
|
|
|
-
|
|
|
- from = PRIVATE;
|
|
|
- }
|
|
|
- else
|
|
|
- if (priv_md5 == NULL) {
|
|
|
-
|
|
|
- from = PUBLIC;
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- xs *pub_fn = xs_fmt("%s/public/%s.json", user->basedir, pub_md5);
|
|
|
- xs *priv_fn = xs_fmt("%s/private/%s.json", user->basedir, priv_md5);
|
|
|
+
|
|
|
+ int newest = -1;
|
|
|
+ double mtime = 0.0;
|
|
|
|
|
|
- if (mtime(pub_fn) < mtime(priv_fn))
|
|
|
- from = PRIVATE;
|
|
|
- else
|
|
|
- from = PUBLIC;
|
|
|
- }
|
|
|
+ for (int n = 0; n < 3; n++) {
|
|
|
+ if (md5s[n] != NULL) {
|
|
|
+ xs *fn = _object_fn_by_md5(md5s[n], "content_search");
|
|
|
+ double mt = mtime(fn);
|
|
|
|
|
|
- if (from == PUBLIC) {
|
|
|
- md5 = pub_md5;
|
|
|
- if (!xs_list_next(pub_tl, &pub_md5, &pub_c))
|
|
|
- pub_md5 = NULL;
|
|
|
- }
|
|
|
- else
|
|
|
- if (from == PRIVATE) {
|
|
|
- md5 = priv_md5;
|
|
|
- if (!xs_list_next(priv_tl, &priv_md5, &priv_c))
|
|
|
- priv_md5 = NULL;
|
|
|
+ if (mt > mtime) {
|
|
|
+ newest = n;
|
|
|
+ mtime = mt;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (md5 == NULL)
|
|
|
+ if (newest == -1)
|
|
|
break;
|
|
|
|
|
|
+ char *md5 = md5s[newest];
|
|
|
+
|
|
|
+
|
|
|
+ if (!xs_list_next(tls[newest], &md5s[newest], &c[newest]))
|
|
|
+ md5s[newest] = NULL;
|
|
|
+
|
|
|
xs *post = NULL;
|
|
|
|
|
|
- if (!valid_status(timeline_get_by_md5(user, md5, &post)))
|
|
|
+ if (!valid_status(object_get_by_md5(md5, &post)))
|
|
|
continue;
|
|
|
|
|
|
if (!xs_match(xs_dict_get_def(post, "type", "-"), POSTLIKE_OBJECT_TYPE))
|
|
@@ -2608,6 +2591,10 @@ xs_list *content_search(snac *user, const char *regex,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ xs_free(tls[0]);
|
|
|
+ xs_free(tls[1]);
|
|
|
+ xs_free(tls[2]);
|
|
|
+
|
|
|
return r;
|
|
|
}
|
|
|
|