From db0a4bff77eb9267cc639c0b21dd9517e4214bef Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 14 Jan 2025 20:15:18 -0500 Subject: [PATCH] ssb: Use most recent post timestamps to feature more relevant people to follow. --- apps/ssb.json | 2 +- apps/ssb/tf-app.js | 35 +++++++++++++++++++++++++++-------- apps/ssb/tf-tab-news-feed.js | 21 +++++++++------------ apps/ssb/tf-tab-news.js | 25 ++++++++++++++----------- 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/apps/ssb.json b/apps/ssb.json index 9d2c8875..e77c8b01 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&ywgXrIlVu5chLPseAwTXdpzaxGep+rjs1ZPeV4tj3wM=.sha256" + "previous": "&IbDnKRKxIZzdIhs2wVVdNt560YlLuM/8coMuTuJhVNs=.sha256" } diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index 057ffa8d..3fd02741 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -163,8 +163,8 @@ class TfElement extends LitElement { let max_row_id = ( await tfrpc.rpc.query( ` - SELECT MAX(rowid) AS max_row_id FROM messages - `, + SELECT MAX(rowid) AS max_row_id FROM messages + `, [] ) )[0].max_row_id; @@ -177,7 +177,7 @@ class TfElement extends LitElement { let abouts = await tfrpc.rpc.query( ` SELECT - messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + messages.author, json(messages.content) AS content, messages.sequence FROM messages, json_each(?1) AS following @@ -188,7 +188,7 @@ class TfElement extends LitElement { json_extract(messages.content, '$.type') = 'about' UNION SELECT - messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature + messages.author, json(messages.content) AS content, messages.sequence FROM messages, json_each(?2) AS following @@ -383,10 +383,9 @@ class TfElement extends LitElement { this.channels_latest = Object.fromEntries( channels.map((x) => [x.channel, x.rowid]) ); - console.log('latest', this.channels_latest); - console.log('unread', this.channels_unread); console.log('channels took', (new Date() - start_time) / 1000.0); let self = this; + start_time = new Date(); latest_private.then(function (latest) { self.channels_latest = Object.assign({}, self.channels_latest, { '🔐': latest, @@ -410,6 +409,24 @@ class TfElement extends LitElement { } } + async fetch_user_info(users) { + let info = await tfrpc.rpc.query( + ` + SELECT messages.author, MAX(messages.sequence) AS max_seq, MAX(timestamp) AS max_ts FROM messages + JOIN json_each(?) AS following + ON messages.author = following.value + GROUP BY messages.author + `, + [ + JSON.stringify(Object.keys(users)), + ]); + for (let row of info) { + users[row.author].seq = row.max_seq; + users[row.author].ts = row.max_ts; + } + return users; + } + async load() { this.loading_latest = true; try { @@ -440,6 +457,9 @@ class TfElement extends LitElement { Object.keys(users).length, 'users' ); + start_time = new Date(); + users = await this.fetch_user_info(users); + console.log('user info took', (new Date() - start_time) / 1000.0, 'seconds'); this.users = users; console.log( `load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}` @@ -573,8 +593,7 @@ class TfElement extends LitElement { style="position: static; top: 0; z-index: 10" >