ssb: Squeeze some blood from the following_perf stone.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
2025-06-11 19:12:59 -04:00
parent 8143a23ced
commit cbf1273a55
2 changed files with 12 additions and 10 deletions

View File

@ -1552,6 +1552,7 @@ typedef struct _following_t following_t;
typedef struct _following_t typedef struct _following_t
{ {
char id[k_id_base64_len]; char id[k_id_base64_len];
bool populated;
following_t** following; following_t** following;
following_t** blocking; following_t** blocking;
int following_count; int following_count;
@ -1559,7 +1560,6 @@ typedef struct _following_t
int depth; int depth;
int ref_count; int ref_count;
int block_ref_count; int block_ref_count;
bool populated;
} following_t; } following_t;
static int _following_compare(const void* a, const void* b) static int _following_compare(const void* a, const void* b)
@ -1745,7 +1745,7 @@ static sqlite3_stmt* _make_following_statement(sqlite3* db)
"SELECT content ->> '$.contact' AS contact, content ->> '$.following', content ->> '$.blocking' " "SELECT content ->> '$.contact' AS contact, content ->> '$.following', content ->> '$.blocking' "
"FROM messages " "FROM messages "
"WHERE author = ? AND content ->> '$.type' = 'contact' AND contact IS NOT NULL " "WHERE author = ? AND content ->> '$.type' = 'contact' AND contact IS NOT NULL "
"ORDER BY content ->> '$.contact', sequence", "ORDER BY sequence",
-1, &statement, NULL) != SQLITE_OK) -1, &statement, NULL) != SQLITE_OK)
{ {
tf_printf("prepare failed: %s", sqlite3_errmsg(db)); tf_printf("prepare failed: %s", sqlite3_errmsg(db));
@ -1778,22 +1778,24 @@ tf_ssb_following_t* tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, in
} }
tf_ssb_following_t* result = tf_malloc(sizeof(tf_ssb_following_t) * (actual_following_count + 1)); tf_ssb_following_t* result = tf_malloc(sizeof(tf_ssb_following_t) * (actual_following_count + 1));
memset(result, 0, sizeof(tf_ssb_following_t) * (actual_following_count + 1));
int write_index = 0; int write_index = 0;
for (int i = 0; i < following_count; i++) for (int i = 0; i < following_count; i++)
{ {
if (following[i]->ref_count > 0 || include_blocks) if (following[i]->ref_count > 0 || include_blocks)
{ {
result[write_index] = (tf_ssb_following_t)
{
.following_count = following[i]->following_count,
.blocking_count = following[i]->blocking_count,
.followed_by_count = following[i]->ref_count,
.blocked_by_count = following[i]->block_ref_count,
.depth = following[i]->depth,
};
tf_string_set(result[write_index].id, sizeof(result[write_index].id), following[i]->id); tf_string_set(result[write_index].id, sizeof(result[write_index].id), following[i]->id);
result[write_index].following_count = following[i]->following_count;
result[write_index].blocking_count = following[i]->blocking_count;
result[write_index].followed_by_count = following[i]->ref_count;
result[write_index].blocked_by_count = following[i]->block_ref_count;
result[write_index].depth = following[i]->depth;
write_index++; write_index++;
} }
} }
result[write_index] = (tf_ssb_following_t) { 0 };
for (int i = 0; i < following_count; i++) for (int i = 0; i < following_count; i++)
{ {

View File

@ -1621,7 +1621,7 @@ void tf_ssb_test_following_perf(const tf_test_options_t* options)
uint64_t start = uv_hrtime(); uint64_t start = uv_hrtime();
int count = 0; int count = 0;
for (int i = 0; i < 100; i++) for (int i = 0; i < 1000; i++)
{ {
const char** ids = tf_ssb_db_get_all_visible_identities(ssb, 2); const char** ids = tf_ssb_db_get_all_visible_identities(ssb, 2);
while (ids[count]) while (ids[count])