ssb: Use most recent post timestamps to feature more relevant people to follow.

This commit is contained in:
2025-01-14 20:15:18 -05:00
parent e198ff9cb1
commit db0a4bff77
4 changed files with 51 additions and 32 deletions

View File

@ -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"
>
<button
class=${'w3-bar-item w3-button w3-circle w3-ripple' +
(this.connections?.some((x) => x.flags.one_shot) ? ' w3-spin' : '')}
class=${'w3-bar-item w3-button w3-circle w3-ripple' + (this.connections?.some(x => x.flags.one_shot) ? ' w3-spin' : '')}
@click=${this.refresh}
>