From 31b78e74df2a2bcb1e63bbe43c568c33557a97eb Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 25 Feb 2025 21:52:15 -0500 Subject: [PATCH] ssb: Following calculation fixes. It was not handled appropriately if an account was encountered multiple times with decreasing depths. --- src/ssb.db.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index 7f011ad7..0f619b18 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -1277,7 +1277,7 @@ static int _following_compare(const void* a, const void* b) static bool _has_following_entry(const char* id, following_t** list, int count) { - return count ? bsearch(id, list, count, sizeof(following_t*), _following_compare) != 0 : false; + return count ? bsearch(id, list, count, sizeof(following_t*), _following_compare) != NULL : false; } static bool _add_following_entry(following_t*** list, int* count, following_t* add) @@ -1432,21 +1432,22 @@ static void _populate_follows_and_blocks(tf_ssb_t* ssb, following_t* entry, foll static void _get_following( tf_ssb_t* ssb, following_t* entry, following_t*** following, int* following_count, int depth, int max_depth, block_node_t* active_blocks, bool include_blocks) { + int old_depth = entry->depth; entry->depth = tf_min(depth, entry->depth); - if (depth < max_depth && !entry->populated && !_is_blocked_by_active_blocks(entry->id, active_blocks)) + if (depth < max_depth && depth < old_depth) { - entry->populated = true; - _populate_follows_and_blocks(ssb, entry, following, following_count, active_blocks, include_blocks); - - if (depth < max_depth) + if (!_is_blocked_by_active_blocks(entry->id, active_blocks)) { + if (!entry->populated) + { + entry->populated = true; + _populate_follows_and_blocks(ssb, entry, following, following_count, active_blocks, include_blocks); + } + block_node_t blocks = { .entry = entry, .parent = active_blocks }; for (int i = 0; i < entry->following_count; i++) { - if (!_has_following_entry(entry->following[i]->id, entry->blocking, entry->blocking_count)) - { - _get_following(ssb, entry->following[i], following, following_count, depth + 1, max_depth, &blocks, include_blocks); - } + _get_following(ssb, entry->following[i], following, following_count, depth + 1, max_depth, &blocks, include_blocks); } } }