configurable ranking
This commit is contained in:
parent
68f298fc21
commit
c9a409845c
|
@ -157,11 +157,11 @@ export async function joinSatRankView (me, models) {
|
|||
if (me) {
|
||||
const user = await models.user.findUnique({ where: { id: me.id } })
|
||||
if (user.wildWestMode) {
|
||||
return 'JOIN sat_rank_wwm_view ON "Item".id = sat_rank_wwm_view.id'
|
||||
return 'JOIN zap_rank_wwm_view ON "Item".id = zap_rank_wwm_view.id'
|
||||
}
|
||||
}
|
||||
|
||||
return 'JOIN sat_rank_tender_view ON "Item".id = sat_rank_tender_view.id'
|
||||
return 'JOIN zap_rank_tender_view ON "Item".id = zap_rank_tender_view.id'
|
||||
}
|
||||
|
||||
export async function filterClause (me, models, type) {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
-- we don't want to have to update our zap_rank views
|
||||
-- when constants change. so we'll just make a view that we can update
|
||||
CREATE OR REPLACE VIEW zap_rank_constants AS
|
||||
SELECT
|
||||
5000.0 AS boost_per_vote,
|
||||
1.2 AS vote_power,
|
||||
1.3 AS vote_decay,
|
||||
3.0 AS age_wait_hours,
|
||||
0.5 AS comment_scaler,
|
||||
2.2 AS boost_power,
|
||||
2.6 AS boost_decay,
|
||||
2100 AS row_limit;
|
||||
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS zap_rank_wwm_view AS
|
||||
SELECT id, rank() OVER (ORDER BY
|
||||
(
|
||||
(GREATEST("weightedVotes", POWER("weightedVotes", vote_power)) + "weightedComments"*comment_scaler)
|
||||
/
|
||||
POWER(GREATEST(age_wait_hours, EXTRACT(EPOCH FROM (now_utc() - created_at))/3600), vote_decay)
|
||||
+
|
||||
POWER(boost/boost_per_vote, boost_power)
|
||||
/
|
||||
POWER(GREATEST(age_wait_hours, EXTRACT(EPOCH FROM (now_utc() - created_at))/3600), boost_decay)
|
||||
) DESC NULLS LAST, id DESC) AS rank
|
||||
FROM "Item", zap_rank_constants
|
||||
WHERE "parentId" IS NULL
|
||||
AND NOT bio
|
||||
AND "pinId" IS NULL
|
||||
AND "deletedAt" IS NULL
|
||||
AND ("weightedVotes" > 0 OR boost > 0)
|
||||
ORDER BY rank ASC
|
||||
LIMIT (SELECT row_limit FROM zap_rank_constants);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS zap_rank_wwm_view_idx ON zap_rank_wwm_view(rank ASC);
|
||||
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS zap_rank_tender_view AS
|
||||
SELECT id, rank() OVER (ORDER BY
|
||||
(
|
||||
(GREATEST(ABS("weightedVotes" - "weightedDownVotes"), POWER(ABS("weightedVotes" - "weightedDownVotes"), vote_power)) + "weightedComments"*comment_scaler)
|
||||
/
|
||||
POWER(GREATEST(age_wait_hours, EXTRACT(EPOCH FROM (now_utc() - created_at))/3600), vote_decay)
|
||||
+
|
||||
POWER(boost/boost_per_vote, boost_power)
|
||||
/
|
||||
POWER(GREATEST(age_wait_hours, EXTRACT(EPOCH FROM (now_utc() - created_at))/3600), boost_decay)
|
||||
) DESC NULLS LAST, id DESC) AS rank
|
||||
FROM "Item", zap_rank_constants
|
||||
WHERE "parentId" IS NULL
|
||||
AND NOT bio
|
||||
AND "pinId" IS NULL
|
||||
AND "deletedAt" IS NULL
|
||||
AND ("weightedVotes" > "weightedDownVotes" OR boost > 0)
|
||||
ORDER BY rank ASC
|
||||
LIMIT (SELECT row_limit FROM zap_rank_constants);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS zap_rank_tender_view_idx ON zap_rank_tender_view(rank ASC);
|
|
@ -18,7 +18,7 @@ function rankViews ({ models }) {
|
|||
return async function () {
|
||||
console.log('refreshing rank views')
|
||||
|
||||
for (const view of ['sat_rank_wwm_view', 'sat_rank_tender_view']) {
|
||||
for (const view of ['zap_rank_wwm_view', 'zap_rank_tender_view']) {
|
||||
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue