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