speed hack hot page
This commit is contained in:
parent
4d1b8bb11e
commit
5bd8025b2b
@ -48,6 +48,25 @@ export default {
|
|||||||
LIMIT ${LIMIT}`, Number(userId), decodedCursor.time, decodedCursor.offset)
|
LIMIT ${LIMIT}`, Number(userId), decodedCursor.time, decodedCursor.offset)
|
||||||
break
|
break
|
||||||
case 'hot':
|
case 'hot':
|
||||||
|
// HACK we can speed hack the first hot page, by limiting our query to only
|
||||||
|
// the most recently created items so that the tables doesn't have to
|
||||||
|
// fully be computed
|
||||||
|
// if the offset is 0, we limit our search to posts from the last week
|
||||||
|
// if there are 21 items, return them ... if not do the unrestricted query
|
||||||
|
// instead of doing this we should materialize a view ... but this is easier for now
|
||||||
|
|
||||||
|
if (decodedCursor.offset === 0) {
|
||||||
|
items = await models.$queryRaw(`
|
||||||
|
${SELECT}
|
||||||
|
FROM "Item"
|
||||||
|
${timedLeftJoinSats(1)}
|
||||||
|
WHERE "parentId" IS NULL AND created_at <= $1 AND created_at > $3
|
||||||
|
${timedOrderBySats(1)}
|
||||||
|
OFFSET $2
|
||||||
|
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset, new Date(new Date() - 7))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (decodedCursor.offset !== 0 || items.length < LIMIT) {
|
||||||
items = await models.$queryRaw(`
|
items = await models.$queryRaw(`
|
||||||
${SELECT}
|
${SELECT}
|
||||||
FROM "Item"
|
FROM "Item"
|
||||||
@ -56,6 +75,7 @@ export default {
|
|||||||
${timedOrderBySats(1)}
|
${timedOrderBySats(1)}
|
||||||
OFFSET $2
|
OFFSET $2
|
||||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
items = await models.$queryRaw(`
|
items = await models.$queryRaw(`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user