diff --git a/apps/ssb.json b/apps/ssb.json index 2f765ae9..45b78a02 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 95621567..118a13ac 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 c658a6c2..16d94277 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;