speed hack notification query
This commit is contained in:
parent
5bd8025b2b
commit
782dc78652
|
@ -42,13 +42,18 @@ export default {
|
||||||
date_trunc('hour', "Vote".created_at) order by created_at desc;
|
date_trunc('hour', "Vote".created_at) order by created_at desc;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// HACK to make notifications faster, we only return a limited sub set of the unioned
|
||||||
|
// queries ... we only ever need at most LIMIT+current offset in the child queries to
|
||||||
|
// have enough items to return in the union
|
||||||
let notifications = await models.$queryRaw(`
|
let notifications = await models.$queryRaw(`
|
||||||
SELECT ${ITEM_FIELDS}, "Item".created_at as "sortTime", NULL as "earnedSats",
|
(SELECT ${ITEM_FIELDS}, "Item".created_at as "sortTime", NULL as "earnedSats",
|
||||||
false as mention
|
false as mention
|
||||||
FROM "Item"
|
FROM "Item"
|
||||||
JOIN "Item" p ON "Item"."parentId" = p.id
|
JOIN "Item" p ON "Item"."parentId" = p.id
|
||||||
WHERE p."userId" = $1
|
WHERE p."userId" = $1
|
||||||
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
|
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
|
||||||
|
ORDER BY "Item".created_at
|
||||||
|
LIMIT ${LIMIT}+$3)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as "sortTime",
|
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as "sortTime",
|
||||||
sum(subquery.sats) as "earnedSats", false as mention
|
sum(subquery.sats) as "earnedSats", false as mention
|
||||||
|
@ -62,7 +67,9 @@ export default {
|
||||||
AND "ItemAct".created_at <= $2
|
AND "ItemAct".created_at <= $2
|
||||||
AND "ItemAct".act <> 'BOOST'
|
AND "ItemAct".act <> 'BOOST'
|
||||||
AND "Item"."userId" = $1) subquery
|
AND "Item"."userId" = $1) subquery
|
||||||
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
|
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island
|
||||||
|
ORDER BY max(subquery.voted_at) desc
|
||||||
|
LIMIT ${LIMIT}+$3)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(SELECT ${ITEM_FIELDS}, "Mention".created_at as "sortTime", NULL as "earnedSats",
|
(SELECT ${ITEM_FIELDS}, "Mention".created_at as "sortTime", NULL as "earnedSats",
|
||||||
true as mention
|
true as mention
|
||||||
|
@ -72,10 +79,12 @@ export default {
|
||||||
WHERE "Mention"."userId" = $1
|
WHERE "Mention"."userId" = $1
|
||||||
AND "Mention".created_at <= $2
|
AND "Mention".created_at <= $2
|
||||||
AND "Item"."userId" <> $1
|
AND "Item"."userId" <> $1
|
||||||
AND (p."userId" IS NULL OR p."userId" <> $1))
|
AND (p."userId" IS NULL OR p."userId" <> $1)
|
||||||
ORDER BY "sortTime" DESC
|
ORDER BY "Mention".created_at
|
||||||
OFFSET $3
|
LIMIT ${LIMIT}+$3)
|
||||||
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
ORDER BY "sortTime" DESC
|
||||||
|
OFFSET $3
|
||||||
|
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
||||||
|
|
||||||
notifications = notifications.map(n => {
|
notifications = notifications.map(n => {
|
||||||
n.item = { ...n }
|
n.item = { ...n }
|
||||||
|
|
|
@ -112,7 +112,10 @@ export default function Header () {
|
||||||
<>
|
<>
|
||||||
<Container className='px-sm-0'>
|
<Container className='px-sm-0'>
|
||||||
<Navbar className={styles.navbar}>
|
<Navbar className={styles.navbar}>
|
||||||
<Nav className='w-100 justify-content-between flex-wrap align-items-center' activeKey={path}>
|
<Nav
|
||||||
|
className={styles.navbarNav}
|
||||||
|
activeKey={path}
|
||||||
|
>
|
||||||
<RefreshableLink href='/' passHref>
|
<RefreshableLink href='/' passHref>
|
||||||
<Navbar.Brand className={`${styles.brand} d-none d-sm-block`}>STACKER NEWS</Navbar.Brand>
|
<Navbar.Brand className={`${styles.brand} d-none d-sm-block`}>STACKER NEWS</Navbar.Brand>
|
||||||
</RefreshableLink>
|
</RefreshableLink>
|
||||||
|
|
|
@ -15,4 +15,11 @@
|
||||||
.navbar {
|
.navbar {
|
||||||
padding: .5rem 0;
|
padding: .5rem 0;
|
||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbarNav {
|
||||||
|
width: 100%;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
Loading…
Reference in New Issue