diff --git a/api/resolvers/item.js b/api/resolvers/item.js index f884a838..6a146329 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -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) + diff --git a/pages/wot.js b/pages/wot.js deleted file mode 100644 index 3dfb54d0..00000000 --- a/pages/wot.js +++ /dev/null @@ -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 ( - - - - ) -}