user new create_item and remove double check for replies

This commit is contained in:
keyan 2023-10-22 12:19:11 -05:00
parent b853cacfa7
commit 4d7d4c28f9
2 changed files with 6 additions and 24 deletions

View File

@ -301,24 +301,6 @@ export default {
} }
} }
// check if they have any replies since checkedNotesAt
const [newReply] = await models.$queryRawUnsafe(`
SELECT EXISTS(
SELECT *
FROM "Item"
JOIN "Item" p ON
${user.noteAllDescendants ? '"Item".path <@ p.path' : '"Item"."parentId" = p.id'}
${whereClause(
'p."userId" = $1',
'"Item"."userId" <> $1',
'"Item".created_at > $2::timestamp(3) without time zone',
await filterClause(me, models),
muteClause(me)
)})`, me.id, lastChecked)
if (newReply.exists) {
return true
}
// break out thread subscription to decrease the search space of the already expensive reply query // break out thread subscription to decrease the search space of the already expensive reply query
const [newThreadSubReply] = await models.$queryRawUnsafe(` const [newThreadSubReply] = await models.$queryRawUnsafe(`
SELECT EXISTS( SELECT EXISTS(

View File

@ -1,6 +1,6 @@
-- migrate old items to ThreadSubscription model -- migrate old items to ThreadSubscription model
INSERT INTO "ThreadSubscription" ("itemId", "userId") INSERT INTO "ThreadSubscription" ("itemId", "userId", created_at)
SELECT "Item".id, "Item"."userId" FROM "Item" ON CONFLICT DO NOTHING; SELECT "Item".id, "Item"."userId", "Item".created_at FROM "Item" ON CONFLICT DO NOTHING;
-- auto self-subscribe -- auto self-subscribe
CREATE OR REPLACE FUNCTION create_item( CREATE OR REPLACE FUNCTION create_item(
@ -29,7 +29,7 @@ BEGIN
cost_msats := 1000 * POWER(10, item_spam(item."parentId", item."userId", spam_within)); cost_msats := 1000 * POWER(10, item_spam(item."parentId", item."userId", spam_within));
END IF; END IF;
-- it's only a freebie if it's a 1 sat cost, they have < 1 sat, and boost = 0 -- it's only a freebie if it's a 1 sat cost, they have < 1 sat, and boost = 0
freebie := (cost_msats <= 1000) AND (user_msats < 1000) AND (item.boost = 0); freebie := (cost_msats <= 1000) AND (user_msats < 1000) AND (item.boost IS NULL OR item.boost = 0);
IF NOT freebie AND cost_msats > user_msats THEN IF NOT freebie AND cost_msats > user_msats THEN
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS'; RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS';
@ -58,10 +58,10 @@ BEGIN
FROM jsonb_object_keys(jsonb_strip_nulls(jitem)) k(key); FROM jsonb_object_keys(jsonb_strip_nulls(jitem)) k(key);
-- insert the item -- insert the item
EXECUTE format($fmt$ EXECUTE format($fmt$
INSERT INTO "Item" (%s, "weightedDownVotes") INSERT INTO "Item" (%s, "weightedDownVotes", freebie)
SELECT %1$s, %L SELECT %1$s, %L, %L
FROM jsonb_populate_record(NULL::"Item", %L) RETURNING * FROM jsonb_populate_record(NULL::"Item", %L) RETURNING *
$fmt$, select_clause, med_votes, jitem) INTO item; $fmt$, select_clause, med_votes, freebie, jitem) INTO item;
INSERT INTO "ItemForward" ("itemId", "userId", "pct") INSERT INTO "ItemForward" ("itemId", "userId", "pct")
SELECT item.id, "userId", "pct" FROM jsonb_populate_recordset(NULL::"ItemForward", forward); SELECT item.id, "userId", "pct" FROM jsonb_populate_recordset(NULL::"ItemForward", forward);