Compare commits
2 Commits
799f22e989
...
1f2664e5a8
Author | SHA1 | Date | |
---|---|---|---|
1f2664e5a8 | |||
35656a5c34 |
@@ -167,16 +167,23 @@ class TfElement extends LitElement {
|
||||
if (ids.indexOf(id) == -1) {
|
||||
delete cache.about[id];
|
||||
} else {
|
||||
users[id] = Object.assign(
|
||||
users[id] || {},
|
||||
cache.about[id]
|
||||
users[id] = Object.assign(users[id] || {}, cache.about[id]);
|
||||
}
|
||||
}
|
||||
|
||||
let ids_out_of_date = ids.filter(
|
||||
(x) =>
|
||||
cache.about[x]?.seq === undefined ||
|
||||
(users[x]?.seq && users[x]?.seq > cache.about[x].seq)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let ids_out_of_date = ids.filter(x => cache.about[x]?.seq === undefined || (users[x]?.seq && users[x]?.seq > cache.about[x].seq));
|
||||
|
||||
console.log('loading about for', ids.length, 'accounts', ids_out_of_date.length, 'out of date');
|
||||
console.log(
|
||||
'loading about for',
|
||||
ids.length,
|
||||
'accounts',
|
||||
ids_out_of_date.length,
|
||||
'out of date'
|
||||
);
|
||||
if (ids_out_of_date.length) {
|
||||
try {
|
||||
let rows = await tfrpc.rpc.query(
|
||||
@@ -219,12 +226,12 @@ class TfElement extends LitElement {
|
||||
if (!cache.about[id]?.seq) {
|
||||
cache.about[id] = {seq: users[id]?.seq ?? 0};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let new_cache = JSON.stringify(cache);
|
||||
if (new_cache != original_cache) {
|
||||
let start_time = new Date();
|
||||
tfrpc.rpc.databaseSet('about', new_cache).then(function() {
|
||||
tfrpc.rpc.databaseSet('about', new_cache).then(function () {
|
||||
console.log('saving about took', (new Date() - start_time) / 1000);
|
||||
});
|
||||
}
|
||||
|
@@ -242,12 +242,11 @@ class TfProfileElement extends LitElement {
|
||||
</div>
|
||||
</div>`
|
||||
: null;
|
||||
let image =profile.image;
|
||||
let image = profile.image;
|
||||
if (typeof image == 'string' && !image.startsWith('&')) {
|
||||
try {
|
||||
image = JSON.parse(image)?.link;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
image = this.editing?.image ?? image;
|
||||
let description = this.editing?.description ?? profile.description;
|
||||
|
@@ -41,8 +41,7 @@ class TfUserElement extends LitElement {
|
||||
if (typeof image_link == 'string' && !image_link.startsWith('&')) {
|
||||
try {
|
||||
image_link = JSON.parse(image_link)?.link;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
if (image_link !== undefined) {
|
||||
image = html`<img
|
||||
|
52
src/ssb.db.c
52
src/ssb.db.c
@@ -1577,17 +1577,9 @@ static following_t* _make_following_node(const char* id, following_t*** followin
|
||||
return entry;
|
||||
}
|
||||
|
||||
static void _populate_follows_and_blocks(tf_ssb_t* ssb, following_t* entry, following_t*** following, int* following_count, block_node_t* active_blocks, bool include_blocks)
|
||||
static void _populate_follows_and_blocks(
|
||||
sqlite3* db, sqlite3_stmt* statement, following_t* entry, following_t*** following, int* following_count, block_node_t* active_blocks, bool include_blocks)
|
||||
{
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
sqlite3_stmt* statement = NULL;
|
||||
if (sqlite3_prepare(db,
|
||||
"SELECT content ->> '$.contact' AS contact, content ->> '$.following', content ->> '$.blocking' "
|
||||
"FROM messages "
|
||||
"WHERE contact IS NOT NULL AND author = ? AND content ->> '$.type' = 'contact' "
|
||||
"ORDER BY sequence",
|
||||
-1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_text(statement, 1, entry->id, -1, NULL) == SQLITE_OK)
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
@@ -1639,13 +1631,11 @@ static void _populate_follows_and_blocks(tf_ssb_t* ssb, following_t* entry, foll
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
sqlite3_reset(statement);
|
||||
}
|
||||
|
||||
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)
|
||||
static void _get_following(sqlite3* db, sqlite3_stmt* statement, 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);
|
||||
@@ -1656,28 +1646,47 @@ static void _get_following(
|
||||
if (!entry->populated)
|
||||
{
|
||||
entry->populated = true;
|
||||
_populate_follows_and_blocks(ssb, entry, following, following_count, active_blocks, include_blocks);
|
||||
_populate_follows_and_blocks(db, statement, 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++)
|
||||
{
|
||||
_get_following(ssb, entry->following[i], following, following_count, depth + 1, max_depth, &blocks, include_blocks);
|
||||
_get_following(db, statement, entry->following[i], following, following_count, depth + 1, max_depth, &blocks, include_blocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static sqlite3_stmt* _make_following_statement(sqlite3* db)
|
||||
{
|
||||
sqlite3_stmt* statement = NULL;
|
||||
if (sqlite3_prepare(db,
|
||||
"SELECT content ->> '$.contact' AS contact, content ->> '$.following', content ->> '$.blocking' "
|
||||
"FROM messages "
|
||||
"WHERE contact IS NOT NULL AND author = ? AND content ->> '$.type' = 'contact' "
|
||||
"ORDER BY sequence",
|
||||
-1, &statement, NULL) != SQLITE_OK)
|
||||
{
|
||||
tf_printf("prepare failed: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
return statement;
|
||||
}
|
||||
|
||||
tf_ssb_following_t* tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, int count, int depth, bool include_blocks)
|
||||
{
|
||||
following_t** following = NULL;
|
||||
int following_count = 0;
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
sqlite3_stmt* statement = _make_following_statement(db);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
following_t* entry = _make_following_node(ids[i], &following, &following_count, NULL, include_blocks);
|
||||
_get_following(ssb, entry, &following, &following_count, 0, depth, NULL, include_blocks);
|
||||
_get_following(db, statement, entry, &following, &following_count, 0, depth, NULL, include_blocks);
|
||||
entry->ref_count++;
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
|
||||
int actual_following_count = 0;
|
||||
for (int i = 0; i < following_count; i++)
|
||||
@@ -1721,12 +1730,17 @@ const char** tf_ssb_db_following_deep_ids(tf_ssb_t* ssb, const char** ids, int c
|
||||
{
|
||||
following_t** following = NULL;
|
||||
int following_count = 0;
|
||||
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
sqlite3_stmt* statement = _make_following_statement(db);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
following_t* entry = _make_following_node(ids[i], &following, &following_count, NULL, false);
|
||||
_get_following(ssb, entry, &following, &following_count, 0, depth, NULL, false);
|
||||
_get_following(db, statement, entry, &following, &following_count, 0, depth, NULL, false);
|
||||
entry->ref_count++;
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
|
||||
int actual_following_count = 0;
|
||||
for (int i = 0; i < following_count; i++)
|
||||
|
Reference in New Issue
Block a user