diff --git a/apps/ssb.json b/apps/ssb.json index 277fa6c8..78c74bb6 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&wzVxQjLzBbwClkI3GB2t85i3pJxRcE1RnCXzC/TbfAw=.sha256" + "previous": "&xT+7rr+XiiHu6hRK+cf15/CCECDyMIp+skvPByaa+eE=.sha256" } diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index 0a43762e..a6b6f949 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -106,50 +106,43 @@ class TfTabNewsFeedElement extends LitElement { [this.hash.substring(1)] ); } else if (this.hash.startsWith('##')) { - let promises = []; - const k_following_limit = 256; - for (let i = 0; i < this.following.length; i += k_following_limit) { - promises.push( - tfrpc.rpc.query( - ` - WITH - all_news AS ( - SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM messages - JOIN json_each(?) AS following ON messages.author = following.value - WHERE messages.content ->> 'channel' = ?4 - UNION - SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM messages_fts(?5) - JOIN messages ON messages.rowid = messages_fts.rowid - JOIN json_each(?1) AS following ON messages.author = following.value - JOIN json_tree(messages.content, '$.mentions') AS mention ON mention.value = '#' || ?4), - news AS (SELECT * FROM all_news - WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 - ORDER BY all_news.timestamp DESC LIMIT 20) - SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM news - JOIN messages_refs ON news.id = messages_refs.ref - JOIN messages ON messages_refs.message = messages.id - UNION - SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM news - JOIN messages_refs ON news.id = messages_refs.message - JOIN messages ON messages_refs.ref = messages.id - UNION - SELECT TRUE AS is_primary, news.* FROM news - `, - [ - JSON.stringify(this.following.slice(i, i + k_following_limit)), - start_time, - end_time, - this.hash.substring(2), - '"#' + this.hash.substring(2).replace('"', '""') + '"', - ] - ) - ); - } - result = [].concat(...(await Promise.all(promises))); + result = await tfrpc.rpc.query( + ` + WITH + all_news AS ( + SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM messages + JOIN json_each(?) AS following ON messages.author = following.value + WHERE messages.content ->> 'channel' = ?4 + UNION + SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM messages_fts(?5) + JOIN messages ON messages.rowid = messages_fts.rowid + JOIN json_each(?1) AS following ON messages.author = following.value + JOIN json_tree(messages.content, '$.mentions') AS mention ON mention.value = '#' || ?4), + news AS (SELECT * FROM all_news + WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 + ORDER BY all_news.timestamp DESC LIMIT 20) + SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM news + JOIN messages_refs ON news.id = messages_refs.ref + JOIN messages ON messages_refs.message = messages.id + UNION + SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM news + JOIN messages_refs ON news.id = messages_refs.message + JOIN messages ON messages_refs.ref = messages.id + UNION + SELECT TRUE AS is_primary, news.* FROM news + `, + [ + JSON.stringify(this.following), + start_time, + end_time, + this.hash.substring(2), + '"#' + this.hash.substring(2).replace('"', '""') + '"', + ] + ); } else if (this.hash == '#🔐') { result = await tfrpc.rpc.query( ` @@ -167,28 +160,28 @@ class TfTabNewsFeedElement extends LitElement { } else { result = await tfrpc.rpc.query( ` - WITH - all_news AS ( - SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM messages - JOIN json_each(?) AS following ON messages.author = following.value - WHERE timestamp >= 0 AND timestamp < ?3), - news AS ( - SELECT * FROM all_news - WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 - ORDER BY timestamp DESC LIMIT 20 - ) - SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM news - JOIN messages_refs ON news.id = messages_refs.ref - JOIN messages ON messages_refs.message = messages.id - UNION - SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature - FROM news - JOIN messages_refs ON news.id = messages_refs.message - JOIN messages ON messages_refs.ref = messages.id - UNION - SELECT TRUE AS is_primary, news.* FROM news + WITH + all_news AS ( + SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM messages + JOIN json_each(?) AS following ON messages.author = following.value + WHERE timestamp >= 0 AND timestamp < ?3), + news AS ( + SELECT * FROM all_news + WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 + ORDER BY timestamp DESC LIMIT 20 + ) + SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM news + JOIN messages_refs ON news.id = messages_refs.ref + JOIN messages ON messages_refs.message = messages.id + UNION + SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + FROM news + JOIN messages_refs ON news.id = messages_refs.message + JOIN messages ON messages_refs.ref = messages.id + UNION + SELECT TRUE AS is_primary, news.* FROM news `, [JSON.stringify(this.following), start_time, end_time] );