From 09f8f1231490c9a0b2aaf199f09d57f406d63b50 Mon Sep 17 00:00:00 2001 From: pory <83127821+pory-gone@users.noreply.github.com> Date: Fri, 25 Jul 2025 16:56:52 +0200 Subject: [PATCH] reduce anon itemCreate cost from 100 to 10 (#2316) * reduce anon itemCreate cost from 100 to 10 * chore: format code with StandardJS --------- Co-authored-by: porygone-z Co-authored-by: ekzyis --- api/paidAction/itemCreate.js | 6 +++--- lib/constants.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/paidAction/itemCreate.js b/api/paidAction/itemCreate.js index d6fb603f..dcdf4d35 100644 --- a/api/paidAction/itemCreate.js +++ b/api/paidAction/itemCreate.js @@ -1,4 +1,4 @@ -import { ANON_ITEM_SPAM_INTERVAL, ITEM_SPAM_INTERVAL, PAID_ACTION_PAYMENT_METHODS, USER_ID } from '@/lib/constants' +import { ANON_ITEM_SPAM_INTERVAL, ANON_FEE_MULTIPLIER, ITEM_SPAM_INTERVAL, PAID_ACTION_PAYMENT_METHODS, USER_ID } from '@/lib/constants' import { notifyItemMention, notifyItemParents, notifyMention, notifyTerritorySubscribers, notifyUserSubscribers, notifyThreadSubscribers } from '@/lib/webPush' import { getItemMentions, getMentions, performBotBehavior } from './lib/item' import { msatsToSats, satsToMsats } from '@/lib/format' @@ -38,12 +38,12 @@ export async function getBaseCost ({ models, bio, parentId, subName }) { export async function getCost ({ subName, parentId, uploadIds, boost = 0, bio }, { models, me }) { const baseCost = await getBaseCost({ models, bio, parentId, subName }) - // cost = baseCost * 10^num_items_in_10m * 100 (anon) or 1 (user) + upload fees + boost + // cost = baseCost * 10^num_items_in_10m * 10 (ANON_FEE_MULTIPLIER constant) or 1 (user) + upload fees + boost const [{ cost }] = await models.$queryRaw` SELECT ${baseCost}::INTEGER * POWER(10, item_spam(${parseInt(parentId)}::INTEGER, ${me?.id ?? USER_ID.anon}::INTEGER, ${me?.id && !bio ? ITEM_SPAM_INTERVAL : ANON_ITEM_SPAM_INTERVAL}::INTERVAL)) - * ${me ? 1 : 100}::INTEGER + * ${me ? 1 : ANON_FEE_MULTIPLIER}::INTEGER + (SELECT "nUnpaid" * "uploadFeesMsats" FROM upload_fees(${me?.id || USER_ID.anon}::INTEGER, ${uploadIds}::INTEGER[])) + ${satsToMsats(boost)}::INTEGER as cost` diff --git a/lib/constants.js b/lib/constants.js index 10ba34f8..76bdf5ca 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -81,7 +81,7 @@ export const ITEM_TYPES_USER = ['all', 'posts', 'comments', 'bounties', 'links', export const ITEM_TYPES = ['all', 'posts', 'comments', 'bounties', 'links', 'discussions', 'polls', 'freebies', 'bios', 'jobs'] export const ITEM_TYPES_UNIVERSAL = ['all', 'posts', 'comments', 'freebies'] export const OLD_ITEM_DAYS = 3 -export const ANON_FEE_MULTIPLIER = 100 +export const ANON_FEE_MULTIPLIER = 10 export const SSR = typeof window === 'undefined' export const MAX_FORWARDS = 5 export const LND_PATHFINDING_TIMEOUT_MS = 30000