Hitting some limit with following too many people. Working around it.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4610 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-11-05 13:07:07 +00:00
parent 6ef14d985d
commit aa10ab69f6
3 changed files with 39 additions and 31 deletions

View File

@ -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;