ssb: Better 'Load More', too.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 20m53s

This commit is contained in:
Cory McWilliams 2025-01-22 18:28:55 -05:00
parent f824b8988e
commit 762b4339fe
2 changed files with 14 additions and 22 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦀", "emoji": "🦀",
"previous": "&LdCd9+kl1DTJIE1+wJ20Yrtpbm15aXvjIBJU3r5Fi38=.sha256" "previous": "&cnc92v8+8JMxSIvs6vZ6j01rUzyVtKg6zkITqwQ02Lc=.sha256"
} }

View File

@ -46,7 +46,6 @@ class TfTabNewsFeedElement extends LitElement {
} }
async fetch_messages(start_time, end_time) { async fetch_messages(start_time, end_time) {
console.log('fetch_messages', this.hash, start_time, end_time);
this.time_loading = [start_time, end_time]; this.time_loading = [start_time, end_time];
let result; let result;
if (this.hash == '#@') { if (this.hash == '#@') {
@ -58,7 +57,7 @@ class TfTabNewsFeedElement extends LitElement {
JOIN json_each(?2) AS following ON messages.author = following.value JOIN json_each(?2) AS following ON messages.author = following.value
WHERE WHERE
messages.author != ?1 AND messages.author != ?1 AND
?3 IS NULL OR (messages.timestamp >= ?3 AND messages.timestamp < ?4) (?3 IS NULL OR messages.timestamp >= ?3) AND messages.timestamp < ?4
ORDER BY timestamp DESC limit 20) 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 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 mentions FROM mentions
@ -78,12 +77,9 @@ class TfTabNewsFeedElement extends LitElement {
result = await tfrpc.rpc.query( result = await tfrpc.rpc.query(
` `
WITH WITH
mine AS (SELECT rowid, id, previous, author, sequence, timestamp, hash, json(content) AS content, signature selected AS (SELECT rowid, id, previous, author, sequence, timestamp, hash, json(content) AS content, signature
FROM messages FROM messages
WHERE messages.author = ?), WHERE messages.author = ?1 AND (?2 IS NULL OR messages.timestamp >= 2) AND messages.timestamp < ?3
selected AS (
SELECT * FROM mine
WHERE ?2 IS NULL OR (mine.timestamp >= 2 AND mine.timestamp < ?3)
ORDER BY sequence DESC LIMIT 20 ORDER BY sequence 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 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
@ -129,7 +125,7 @@ class TfTabNewsFeedElement extends LitElement {
JOIN json_each(?1) AS following ON messages.author = following.value JOIN json_each(?1) AS following ON messages.author = following.value
JOIN json_tree(messages.content, '$.mentions') AS mention ON mention.value = '#' || ?4), JOIN json_tree(messages.content, '$.mentions') AS mention ON mention.value = '#' || ?4),
news AS (SELECT * FROM all_news news AS (SELECT * FROM all_news
WHERE ?2 IS NULL OR (all_news.timestamp >= ?2 AND all_news.timestamp < ?3) WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3
ORDER BY all_news.timestamp DESC LIMIT 20) 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 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 FROM news
@ -161,7 +157,7 @@ class TfTabNewsFeedElement extends LitElement {
FROM messages FROM messages
JOIN json_each(?1) AS following ON messages.author = following.value JOIN json_each(?1) AS following ON messages.author = following.value
WHERE WHERE
?2 IS NULL OR (messages.timestamp >= ?2 AND messages.timestamp < ?3) AND (?2 IS NULL OR (messages.timestamp >= ?2) AND messages.timestamp < ?3 AND
json(messages.content) LIKE '"%' json(messages.content) LIKE '"%'
ORDER BY sequence DESC LIMIT 20 ORDER BY sequence DESC LIMIT 20
`, `,
@ -179,7 +175,7 @@ class TfTabNewsFeedElement extends LitElement {
WHERE timestamp >= 0 AND timestamp < ?3), WHERE timestamp >= 0 AND timestamp < ?3),
news AS ( news AS (
SELECT * FROM all_news SELECT * FROM all_news
WHERE ?2 IS NULL or (all_news.timestamp >= ?2 AND all_news.timestamp < ?3) WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3
ORDER BY timestamp DESC LIMIT 20 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 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
@ -224,17 +220,13 @@ class TfTabNewsFeedElement extends LitElement {
this.loading_canceled = false; this.loading_canceled = false;
try { try {
let more = []; let more = [];
while (!more.length && !this.loading_canceled) { let last_start_time = this.time_range[0];
let last_start_time = this.start_time; more = await this.fetch_messages(null, last_start_time);
this.start_time = last_start_time - 7 * 24 * 60 * 60 * 1000; this.update_time_range_from_messages(
more = await this.fetch_messages(this.start_time, last_start_time); more.filter(
this.update_time_range_from_messages( (x) => x.timestamp < last_start_time
more.filter( )
(x) => );
x.timestamp >= this.start_time && x.timestamp < last_start_time
)
);
}
this.messages = await this.decrypt([...more, ...this.messages]); this.messages = await this.decrypt([...more, ...this.messages]);
} finally { } finally {
this.loading--; this.loading--;