Fix feed replication. Ugh, Cory.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4104 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-01-04 02:59:35 +00:00
parent 8ed359327c
commit ff06e91ac8
2 changed files with 31 additions and 22 deletions

View File

@ -320,6 +320,9 @@ function ebtReplicateServer(request) {
ssb.addRpc(['ebt', 'replicate'], ebtReplicateServer);
ssb.addRpc(['createHistoryStream'], function(request) {
if (!request?.args) {
print('missing request.args in createHistoryStream');
}
var id = request.args[0].id;
var seq = request.args[0].seq;
var keys = request.args[0].keys || request.args[0].keys === undefined;

View File

@ -1010,9 +1010,15 @@ static following_t* _get_following(tf_ssb_t* ssb, const char* id, following_t***
{
int index = tf_util_insert_index(id, *following, *following_count, sizeof(following_t*), _following_compare);
following_t* entry = NULL;
bool already_populated = false;
if (index < *following_count && strcmp(id, (*following)[index]->id) == 0)
{
entry = (*following)[index];
already_populated = entry->depth < max_depth;
if (depth < entry->depth)
{
entry->depth = depth;
}
}
else
{
@ -1027,40 +1033,40 @@ static following_t* _get_following(tf_ssb_t* ssb, const char* id, following_t***
memset(entry, 0, sizeof(*entry));
snprintf(entry->id, sizeof(entry->id), "%s", id);
entry->depth = depth;
}
if (depth < max_depth)
if (depth < max_depth && !already_populated)
{
sqlite3* db = tf_ssb_get_db(ssb);
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare(db, "SELECT json_extract(content, '$.contact'), json_extract(content, '$.following'), json_extract(content, '$.blocking') FROM messages WHERE author = ? AND json_extract(content, '$.type') = 'contact' ORDER BY sequence", -1, &statement, NULL) == SQLITE_OK)
{
sqlite3* db = tf_ssb_get_db(ssb);
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare(db, "SELECT json_extract(content, '$.contact'), json_extract(content, '$.following'), json_extract(content, '$.blocking') FROM messages WHERE author = ? AND json_extract(content, '$.type') = 'contact' ORDER BY sequence", -1, &statement, NULL) == SQLITE_OK)
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
while (sqlite3_step(statement) == SQLITE_ROW)
{
while (sqlite3_step(statement) == SQLITE_ROW)
const char* contact = (const char*)sqlite3_column_text(statement, 0);
if (sqlite3_column_type(statement, 1) != SQLITE_NULL)
{
const char* contact = (const char*)sqlite3_column_text(statement, 0);
if (sqlite3_column_type(statement, 1) != SQLITE_NULL)
bool is_following = sqlite3_column_int(statement, 1);
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, max_depth);
if (is_following)
{
bool is_following = sqlite3_column_int(statement, 1);
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, max_depth);
if (is_following)
{
_add_following_entry(&entry->following, &entry->following_count, next);
}
_add_following_entry(&entry->following, &entry->following_count, next);
}
if (sqlite3_column_type(statement, 2) != SQLITE_NULL)
}
if (sqlite3_column_type(statement, 2) != SQLITE_NULL)
{
bool is_blocking = sqlite3_column_int(statement, 2);
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, 0 /* don't dig deeper into blocked users */);
if (is_blocking)
{
bool is_blocking = sqlite3_column_int(statement, 2);
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, 0 /* don't dig deeper into blocked users */);
if (is_blocking)
{
_add_following_entry(&entry->blocking, &entry->blocking_count, next);
}
_add_following_entry(&entry->blocking, &entry->blocking_count, next);
}
}
}
sqlite3_finalize(statement);
}
sqlite3_finalize(statement);
}
}
return entry;