make boost more expensive
This commit is contained in:
parent
a7a72f0d2d
commit
8b1a923ac1
|
@ -4,6 +4,7 @@ import serialize from './serial'
|
||||||
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
||||||
import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
|
import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
|
||||||
import domino from 'domino'
|
import domino from 'domino'
|
||||||
|
import { BOOST_MIN } from '../../lib/constants'
|
||||||
|
|
||||||
async function comments (models, id, sort) {
|
async function comments (models, id, sort) {
|
||||||
let orderBy
|
let orderBy
|
||||||
|
@ -817,8 +818,8 @@ const createItem = async (parent, { title, url, text, boost, parentId }, { me, m
|
||||||
throw new AuthenticationError('you must be logged in')
|
throw new AuthenticationError('you must be logged in')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boost && boost < 0) {
|
if (boost && boost < BOOST_MIN) {
|
||||||
throw new UserInputError('boost must be positive', { argumentName: 'boost' })
|
throw new UserInputError(`boost must be at least ${BOOST_MIN}`, { argumentName: 'boost' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if they've already commented on this parent ... don't allow it if so
|
// check if they've already commented on this parent ... don't allow it if so
|
||||||
|
@ -877,15 +878,6 @@ export const SELECT =
|
||||||
"Item".company, "Item".location, "Item".remote,
|
"Item".company, "Item".location, "Item".remote,
|
||||||
"Item"."subName", "Item".status, ltree2text("Item"."path") AS "path"`
|
"Item"."subName", "Item".status, ltree2text("Item"."path") AS "path"`
|
||||||
|
|
||||||
const LEFT_JOIN_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost'
|
|
||||||
|
|
||||||
// function timedLeftJoinSats (num) {
|
|
||||||
// return `LEFT JOIN (${LEFT_JOIN_SATS_SELECT}
|
|
||||||
// FROM "Item" i
|
|
||||||
// JOIN "ItemAct" ON i.id = "ItemAct"."itemId" AND "ItemAct".created_at <= $${num}
|
|
||||||
// GROUP BY i.id) x ON "Item".id = x.id`
|
|
||||||
// }
|
|
||||||
|
|
||||||
const LEFT_JOIN_WEIGHTED_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats * users.trust ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost'
|
const LEFT_JOIN_WEIGHTED_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats * users.trust ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost'
|
||||||
|
|
||||||
function timedLeftJoinWeightedSats (num) {
|
function timedLeftJoinWeightedSats (num) {
|
||||||
|
@ -900,23 +892,19 @@ function timedLeftJoinWeightedSats (num) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const LEFT_JOIN_WEIGHTED_SATS =
|
const LEFT_JOIN_WEIGHTED_SATS =
|
||||||
`LEFT JOIN (${LEFT_JOIN_SATS_SELECT}
|
`LEFT JOIN (
|
||||||
|
${LEFT_JOIN_WEIGHTED_SATS_SELECT}
|
||||||
FROM "Item" i
|
FROM "Item" i
|
||||||
JOIN "ItemAct" ON i.id = "ItemAct"."itemId"
|
JOIN "ItemAct" ON i.id = "ItemAct"."itemId"
|
||||||
GROUP BY i.id) x ON "Item".id = x.id`
|
JOIN users on "ItemAct"."userId" = users.id
|
||||||
|
GROUP BY i.id
|
||||||
// const LEFT_JOIN_SATS =
|
) x ON "Item".id = x.id`
|
||||||
// `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 */
|
/* NOTE: because many items will have the same rank, we need to tie break with a unique field so pagination works */
|
||||||
function timedOrderBySats (num) {
|
function timedOrderBySats (num) {
|
||||||
return `ORDER BY (GREATEST(x.sats-1, 0)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 1.5) +
|
return `ORDER BY (GREATEST(x.sats-1, 0)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 1.5) +
|
||||||
(x.boost)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 5)) DESC NULLS LAST, "Item".id DESC`
|
GREATEST(x.boost-${BOOST_MIN}+5, 0)/POWER(EXTRACT(EPOCH FROM ($${num} - "Item".created_at))/3600+2, 5)) DESC NULLS LAST, "Item".id DESC`
|
||||||
}
|
}
|
||||||
|
|
||||||
const ORDER_BY_SATS =
|
const ORDER_BY_SATS =
|
||||||
`ORDER BY ((x.sats-1)/POWER(EXTRACT(EPOCH FROM ((NOW() AT TIME ZONE 'UTC') - "Item".created_at))/3600+2, 1.5) +
|
'ORDER BY GREATEST(x.sats-1, 0)/POWER(EXTRACT(EPOCH FROM ((NOW() AT TIME ZONE \'UTC\') - "Item".created_at))/3600+2, 1.5) DESC NULLS LAST, "Item".id DESC'
|
||||||
(x.boost)/POWER(EXTRACT(EPOCH FROM ((NOW() AT TIME ZONE 'UTC') - "Item".created_at))/3600+2, 5)) DESC NULLS LAST, "Item".id DESC`
|
|
||||||
|
|
|
@ -2,14 +2,15 @@ import AccordianItem from './accordian-item'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { Input } from './form'
|
import { Input } from './form'
|
||||||
import { InputGroup } from 'react-bootstrap'
|
import { InputGroup } from 'react-bootstrap'
|
||||||
|
import { BOOST_MIN } from '../lib/constants'
|
||||||
|
|
||||||
export const AdvPostSchema = {
|
export const AdvPostSchema = {
|
||||||
boost: Yup.number().typeError('must be a number')
|
boost: Yup.number().typeError('must be a number')
|
||||||
.min(0, 'must be positive').integer('must be whole')
|
.min(BOOST_MIN, `must be at least ${BOOST_MIN}`).integer('must be whole')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AdvPostInitial = {
|
export const AdvPostInitial = {
|
||||||
boost: 0
|
boost: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AdvPostForm () {
|
export default function AdvPostForm () {
|
||||||
|
|
|
@ -72,7 +72,8 @@ export default function JobForm ({ item, sub }) {
|
||||||
.or([Yup.string().email(), Yup.string().url()], 'invalid url or email')
|
.or([Yup.string().email(), Yup.string().url()], 'invalid url or email')
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
maxBid: Yup.number('must be number')
|
maxBid: Yup.number('must be number')
|
||||||
.integer('must be integer').min(sub.baseCost, `must be at least ${sub.baseCost}`),
|
.integer('must be whole').min(sub.baseCost, `must be at least ${sub.baseCost}`)
|
||||||
|
.required('required'),
|
||||||
location: Yup.string().when('remote', {
|
location: Yup.string().when('remote', {
|
||||||
is: (value) => !value,
|
is: (value) => !value,
|
||||||
then: Yup.string().required('required').trim()
|
then: Yup.string().required('required').trim()
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
export const NOFOLLOW_LIMIT = 10
|
export const NOFOLLOW_LIMIT = 100
|
||||||
|
export const BOOST_MIN = 1000
|
||||||
|
|
Loading…
Reference in New Issue