From b2f5f95c7b8c8793f82d394009b0908888de5bdc Mon Sep 17 00:00:00 2001 From: default Date: Sat, 25 Jan 2025 23:06:08 +0100 Subject: Fixed repeated entries in the instance public timeline. --- data.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 33947ff..40382d2 100644 --- a/data.c +++ b/data.c @@ -1399,11 +1399,13 @@ void timeline_update_indexes(snac *snac, const char *id) if (valid_status(object_get(id, &msg))) { /* if its ours and is public, also store in public */ if (is_msg_public(msg)) { - object_user_cache_add(snac, id, "public"); - - /* also add it to the instance public timeline */ - xs *ipt = xs_fmt("%s/public.idx", srv_basedir); - index_add(ipt, id); + if (object_user_cache_add(snac, id, "public") >= 0) { + /* also add it to the instance public timeline */ + xs *ipt = xs_fmt("%s/public.idx", srv_basedir); + index_add(ipt, id); + } + else + srv_debug(1, xs_fmt("Not added to public instance index %s", id)); } } } @@ -1524,8 +1526,17 @@ xs_list *timeline_instance_list(int skip, int show) /* returns the timeline for the full instance */ { xs *idx = instance_index_fn(); + xs *lst = index_list_desc(idx, skip, show); - return index_list_desc(idx, skip, show); + /* make the list unique */ + xs_set rep; + xs_set_init(&rep); + const char *md5; + + xs_list_foreach(lst, md5) + xs_set_add(&rep, md5); + + return xs_set_result(&rep); } -- cgit v1.2.3 From 82bcc4b465f73a5d1f2eebcf3813452bc1c37fbd Mon Sep 17 00:00:00 2001 From: default Date: Mon, 27 Jan 2025 16:59:08 +0100 Subject: Minor optimization in timeline retrieving. Functions now receive an optional int *more, set to 1 if there are more than the 'show' requested. --- data.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 40382d2..550f7cf 100644 --- a/data.c +++ b/data.c @@ -1489,16 +1489,28 @@ xs_str *user_index_fn(snac *user, const char *idx_name) } -xs_list *timeline_simple_list(snac *user, const char *idx_name, int skip, int show) +xs_list *timeline_simple_list(snac *user, const char *idx_name, int skip, int show, int *more) /* returns a timeline (with all entries) */ { xs *idx = user_index_fn(user, idx_name); - return index_list_desc(idx, skip, show); + /* if a more flag is sent, request one more */ + xs_list *lst = index_list_desc(idx, skip, show + (more != NULL ? 1 : 0)); + + if (more != NULL) { + if (xs_list_len(lst) > show) { + *more = 1; + lst = xs_list_del(lst, -1); + } + else + *more = 0; + } + + return lst; } -xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show) +xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show, int *more) /* returns a timeline (only top level entries) */ { int c_max; @@ -1510,7 +1522,7 @@ xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show) if (show > c_max) show = c_max; - xs *list = timeline_simple_list(snac, idx_name, skip, show); + xs *list = timeline_simple_list(snac, idx_name, skip, show, more); return timeline_top_level(snac, list); } @@ -2709,9 +2721,9 @@ xs_list *content_search(snac *user, const char *regex, const char *md5s[3] = {0}; int c[3] = {0}; - tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */ + tls[0] = timeline_simple_list(user, "public", 0, XS_ALL, NULL); /* public */ tls[1] = timeline_instance_list(0, XS_ALL); /* instance */ - tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new(); /* private or none */ + tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL, NULL) : xs_list_new(); /* private or none */ /* first positioning */ for (int n = 0; n < 3; n++) -- cgit v1.2.3 From 1766d6bf92eb433841c03ccb096c636a4c5dc968 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 27 Jan 2025 20:20:40 +0100 Subject: Added a 'No more unseen posts' mark. --- data.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 550f7cf..480a35b 100644 --- a/data.c +++ b/data.c @@ -1528,6 +1528,14 @@ xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show, int } +void timeline_add_mark(snac *user) +/* adds an "already seen" mark to the private timeline */ +{ + xs *fn = xs_fmt("%s/private.idx", user->basedir); + index_add_md5(fn, MD5_ALREADY_SEEN_MARK); +} + + xs_str *instance_index_fn(void) { return xs_fmt("%s/public.idx", srv_basedir); -- cgit v1.2.3 From 06ba1174ca7084a3d691aa8c2b552b708d04b8db Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Jan 2025 10:04:23 +0100 Subject: Some tweaks to the already seen mark code. --- data.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 480a35b..7139cdf 100644 --- a/data.c +++ b/data.c @@ -1532,7 +1532,23 @@ void timeline_add_mark(snac *user) /* adds an "already seen" mark to the private timeline */ { xs *fn = xs_fmt("%s/private.idx", user->basedir); - index_add_md5(fn, MD5_ALREADY_SEEN_MARK); + char last_entry[MD5_HEX_SIZE] = ""; + FILE *f; + + /* get the last entry in the index */ + if ((f = fopen(fn, "r")) != NULL) { + index_desc_first(f, last_entry, 0); + fclose(f); + } + + /* is the last entry *not* a mark? */ + if (strcmp(last_entry, MD5_ALREADY_SEEN_MARK) != 0) { + /* add it */ + index_add_md5(fn, MD5_ALREADY_SEEN_MARK); + + /* mark as new */ + timeline_touch(user); + } } -- cgit v1.2.3 From aec643838f304468af61ca2ad4e00a9e7125e53b Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Jan 2025 20:36:37 +0100 Subject: Deleted useless code. --- data.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 7139cdf..50c6121 100644 --- a/data.c +++ b/data.c @@ -1545,9 +1545,6 @@ void timeline_add_mark(snac *user) if (strcmp(last_entry, MD5_ALREADY_SEEN_MARK) != 0) { /* add it */ index_add_md5(fn, MD5_ALREADY_SEEN_MARK); - - /* mark as new */ - timeline_touch(user); } } -- cgit v1.2.3 From 4df4f0c5518cfe8ae90d098612e9d131f4a384f5 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 5 Feb 2025 09:47:38 +0100 Subject: Fixed bug in search. --- data.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 50c6121..2f1a52b 100644 --- a/data.c +++ b/data.c @@ -2766,7 +2766,17 @@ xs_list *content_search(snac *user, const char *regex, 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); + double mt; + + while ((mt = mtime(fn)) == 0 && md5s[n] != NULL) { + /* object is not here: move to the next one */ + if (xs_list_next(tls[n], &md5s[n], &c[n])) { + xs_free(fn); + fn = _object_fn_by_md5(md5s[n], "content_search_2"); + } + else + md5s[n] = NULL; + } if (mt > mtime) { newest = n; -- cgit v1.2.3 From 22a23dbdd1fca4695c012c31d5e5502f38212ed8 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 6 Feb 2025 10:56:21 +0100 Subject: Minor tweak to inbox_list(). --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 2f1a52b..9fc54a0 100644 --- a/data.c +++ b/data.c @@ -2601,7 +2601,7 @@ xs_list *inbox_list(void) if ((f = fopen(v, "r")) != NULL) { xs *line = xs_readline(f); - if (line) { + if (line && *line) { line = xs_strip_i(line); ibl = xs_list_append(ibl, line); } -- cgit v1.2.3