From aa10ab69f6f42cc5364acd14b84c3b2c7a12e2c5 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 5 Nov 2023 13:07:07 +0000 Subject: [PATCH] Hitting some limit with following too many people. Working around it. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4610 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/ssb.json | 2 +- apps/ssb/tf-app.js | 4 ++- apps/ssb/tf-tab-news-feed.js | 64 ++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/apps/ssb.json b/apps/ssb.json index 2f765ae98..45b78a02e 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🐌", - "previous": "&qvm+scemENl4DobpOoh/UyILGvvx5NbcPJKTU3CswSE=.sha256" + "previous": "&tx4iQew0sHvZW3YAEx8y2Qr8m+MhoNdxs/5+1Rx4s7Y=.sha256" } \ No newline at end of file diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index 956215676..118a13ac7 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -212,8 +212,8 @@ class TfElement extends LitElement { let whoami = this.whoami; let tags = this.load_recent_tags(); let following = await tfrpc.rpc.following([whoami], 2); - console.log(following); let users = {}; + let by_count = []; for (let [id, v] of Object.entries(following)) { users[id] = { following: v.of, @@ -221,7 +221,9 @@ class TfElement extends LitElement { followed: v.if, blocked: v.ib, }; + by_count.push({count: v.of, id: id}); } + console.log(by_count.sort((x, y) => y.count - x.count).slice(0, 20)); users = await this.fetch_about(Object.keys(following).sort(), users); this.following = Object.keys(following); this.users = users; diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index c658a6c25..16d942772 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -65,34 +65,39 @@ class TfTabNewsFeedElement extends LitElement { this.hash.substring(1), ]); } else { - return await tfrpc.rpc.query( - ` - WITH news AS (SELECT messages.* - FROM messages - JOIN json_each(?) AS following ON messages.author = following.value - WHERE messages.timestamp > ? AND messages.timestamp < ? - ORDER BY messages.timestamp DESC) - SELECT messages.* - FROM news - JOIN messages_refs ON news.id = messages_refs.ref - JOIN messages ON messages_refs.message = messages.id - UNION - SELECT messages.* - FROM news - JOIN messages_refs ON news.id = messages_refs.message - JOIN messages ON messages_refs.ref = messages.id - UNION - SELECT news.* FROM news - `, - [ - JSON.stringify(this.following), - this.start_time, - /* - ** Don't show messages more than a day into the future to prevent - ** messages with far-future timestamps from staying at the top forever. - */ - new Date().valueOf() + 24 * 60 * 60 * 1000, - ]); + let messages = []; + const k_following_limit = 2048; + for (let i = 0; i < this.following.length; i += k_following_limit) { + messages = messages.concat(await tfrpc.rpc.query( + ` + WITH news AS (SELECT messages.* + FROM messages + JOIN json_each(?) AS following ON messages.author = following.value + WHERE messages.timestamp > ? AND messages.timestamp < ? + ORDER BY messages.timestamp DESC) + SELECT messages.* + FROM news + JOIN messages_refs ON news.id = messages_refs.ref + JOIN messages ON messages_refs.message = messages.id + UNION + SELECT messages.* + FROM news + JOIN messages_refs ON news.id = messages_refs.message + JOIN messages ON messages_refs.ref = messages.id + UNION + SELECT news.* FROM news + `, + [ + JSON.stringify(this.following.slice(i, i + k_following_limit)), + this.start_time, + /* + ** Don't show messages more than a day into the future to prevent + ** messages with far-future timestamps from staying at the top forever. + */ + new Date().valueOf() + 24 * 60 * 60 * 1000, + ])); + } + return messages; } } @@ -128,6 +133,7 @@ class TfTabNewsFeedElement extends LitElement { } async decrypt(messages) { + console.log('decrypt'); let result = []; for (let message of messages) { let content; @@ -162,7 +168,7 @@ class TfTabNewsFeedElement extends LitElement { if (!this.messages || this._messages_hash !== this.hash || this._messages_following !== this.following) { - console.log(`loading messages for ${this.whoami}`); + console.log(`loading messages for ${this.whoami} (following ${this.following.length})`); let self = this; this.messages = []; this._messages_hash = this.hash;