forked from cory/tildefriends
Try showing the last day's worth of posts.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3868 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -259,6 +259,42 @@ async function getRecentPostIds(db, id, ids, limit) {
|
||||
return f.recent.map(x => x.id);
|
||||
}
|
||||
|
||||
async function getRecentPostIds2(db, id, ids, start_time) {
|
||||
const k_batch_max = 32;
|
||||
var row_id_max = 0;
|
||||
await ssb.sqlStream(
|
||||
"SELECT MAX(rowid) as rowid FROM messages",
|
||||
[],
|
||||
function(row) {
|
||||
row_id_max = row.rowid;
|
||||
});
|
||||
var posts_by_author = {};
|
||||
for (var i = 0; i < ids.length; i += k_batch_max) {
|
||||
var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length));
|
||||
await ssb.sqlStream(
|
||||
"SELECT "+
|
||||
" author, "+
|
||||
" id "+
|
||||
"FROM messages "+
|
||||
"WHERE "+
|
||||
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
|
||||
" timestamp > ? AND "+
|
||||
" rowid <= ? AND "+
|
||||
" json_extract(content, '$.type') = 'post' "+
|
||||
"ORDER BY timestamp",
|
||||
[].concat(ids_batch, [start_time, row_id_max]),
|
||||
function(row) {
|
||||
if (row.id) {
|
||||
if (!posts_by_author[row.author]) {
|
||||
posts_by_author[row.author] = [];
|
||||
}
|
||||
posts_by_author[row.author].push(row.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
return Object.values(posts_by_author).map(x => x[0]);
|
||||
}
|
||||
|
||||
async function getRelatedPostIds(db, message, ids, limit) {
|
||||
const k_batch_max = 16;
|
||||
var recent = [];
|
||||
@ -430,7 +466,7 @@ async function refresh(selected) {
|
||||
m = m.length ? m[0] : {id: selected[0]};
|
||||
ids = await getRelatedPostIds(db, m, all_followed, k_posts_max);
|
||||
} else {
|
||||
ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
|
||||
ids = await getRecentPostIds2(db, whoami, g_selected, (new Date()).valueOf() - (24 * 60 * 60 * 1000));
|
||||
}
|
||||
timing.push({name: 'get_post_ids', time: new Date()});
|
||||
var posts = await getPosts(db, ids);
|
||||
|
Reference in New Issue
Block a user