make wot ranking live + wot ranked comments
This commit is contained in:
parent
15cf95fa01
commit
dce189703c
|
@ -11,7 +11,7 @@ async function comments (models, id, sort) {
|
|||
switch (sort) {
|
||||
case 'top':
|
||||
orderBy = 'ORDER BY x.sats DESC NULLS LAST'
|
||||
join = LEFT_JOIN_SATS
|
||||
join = LEFT_JOIN_WEIGHTED_SATS
|
||||
break
|
||||
case 'recent':
|
||||
orderBy = 'ORDER BY "Item".created_at DESC'
|
||||
|
@ -19,7 +19,7 @@ async function comments (models, id, sort) {
|
|||
break
|
||||
default:
|
||||
orderBy = ORDER_BY_SATS
|
||||
join = LEFT_JOIN_SATS
|
||||
join = LEFT_JOIN_WEIGHTED_SATS
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -107,26 +107,26 @@ export default {
|
|||
|
||||
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
|
||||
AND "pinId" IS NULL
|
||||
${timedOrderBySats(1)}
|
||||
OFFSET $2
|
||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset, new Date(new Date() - 7))
|
||||
${SELECT}
|
||||
FROM "Item"
|
||||
${timedLeftJoinWeightedSats(1)}
|
||||
WHERE "parentId" IS NULL AND created_at <= $1 AND created_at > $3
|
||||
AND "pinId" IS NULL
|
||||
${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(`
|
||||
${SELECT}
|
||||
FROM "Item"
|
||||
${timedLeftJoinSats(1)}
|
||||
WHERE "parentId" IS NULL AND created_at <= $1
|
||||
AND "pinId" IS NULL
|
||||
${timedOrderBySats(1)}
|
||||
OFFSET $2
|
||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||
${SELECT}
|
||||
FROM "Item"
|
||||
${timedLeftJoinWeightedSats(1)}
|
||||
WHERE "parentId" IS NULL AND created_at <= $1
|
||||
AND "pinId" IS NULL
|
||||
${timedOrderBySats(1)}
|
||||
OFFSET $2
|
||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||
}
|
||||
|
||||
if (decodedCursor.offset === 0) {
|
||||
|
@ -143,17 +143,6 @@ export default {
|
|||
) rank_filter WHERE RANK = 1`)
|
||||
}
|
||||
break
|
||||
case 'wot':
|
||||
items = await models.$queryRaw(`
|
||||
${SELECT}
|
||||
FROM "Item"
|
||||
${timedLeftJoinWeightedSats(1)}
|
||||
WHERE "parentId" IS NULL AND created_at <= $1
|
||||
AND "pinId" IS NULL
|
||||
${timedOrderBySats(1)}
|
||||
OFFSET $2
|
||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||
break
|
||||
case 'top':
|
||||
items = await models.$queryRaw(`
|
||||
${SELECT}
|
||||
|
@ -730,12 +719,18 @@ function timedLeftJoinWeightedSats (num) {
|
|||
) x ON "Item".id = x.id`
|
||||
}
|
||||
|
||||
const LEFT_JOIN_SATS =
|
||||
const LEFT_JOIN_WEIGHTED_SATS =
|
||||
`LEFT JOIN (${LEFT_JOIN_SATS_SELECT}
|
||||
FROM "Item" i
|
||||
JOIN "ItemAct" ON i.id = "ItemAct"."itemId"
|
||||
GROUP BY i.id) x ON "Item".id = x.id`
|
||||
|
||||
// const LEFT_JOIN_SATS =
|
||||
// `LEFT JOIN (${LEFT_JOIN_SATS_SELECT}
|
||||
// FROM "Item" i
|
||||
// JOIN "ItemAct" ON i.id = "ItemAct"."itemId"
|
||||
// GROUP BY i.id) x ON "Item".id = x.id`
|
||||
|
||||
/* NOTE: because many items will have the same rank, we need to tie break with a unique field so pagination works */
|
||||
function timedOrderBySats (num) {
|
||||
return `ORDER BY (GREATEST(x.sats-1, 0)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 1.5) +
|
||||
|
|
18
pages/wot.js
18
pages/wot.js
|
@ -1,18 +0,0 @@
|
|||
import Layout from '../components/layout'
|
||||
import Items from '../components/items'
|
||||
import { getGetServerSideProps } from '../api/ssrApollo'
|
||||
import { MORE_ITEMS } from '../fragments/items'
|
||||
|
||||
const variables = { sort: 'wot' }
|
||||
export const getServerSideProps = getGetServerSideProps(MORE_ITEMS, variables)
|
||||
|
||||
export default function Index ({ data: { moreItems: { items, pins, cursor } } }) {
|
||||
return (
|
||||
<Layout>
|
||||
<Items
|
||||
items={items} pins={pins} cursor={cursor}
|
||||
variables={variables} rank
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue