try to fix active stocks losing price updates
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s

This commit is contained in:
2026-03-21 21:47:47 -04:00
parent e2dc3ea492
commit 34ecec2da6
+20 -7
View File
@@ -144,25 +144,38 @@ const priceWorker = new Worker(
} }
const shouldDeactivate = ttlExpired && ownerCount === 0 const shouldDeactivate = ttlExpired && ownerCount === 0
await prisma.hashtag.update({ const floorPrice = calcPrice(0)
await prisma.$transaction([
prisma.hashtag.update({
where: { id: hashtagId }, where: { id: hashtagId },
data: { data: {
zeroCount: newZeroCount, zeroCount: newZeroCount,
isActive: shouldDeactivate ? false : hashtag.isActive, isActive: shouldDeactivate ? false : hashtag.isActive,
lastUpdated: new Date(), lastUpdated: new Date(),
}, },
}) }),
// Record floor price in history while the stock is still active so the chart has no gaps
...(!shouldDeactivate ? [prisma.priceHistory.create({
data: { hashtagId, price: floorPrice, postsPerHour: 0 },
})] : []),
])
console.log(`[price] #${tag} got 0 posts (zeroCount=${newZeroCount})${shouldDeactivate ? ' — deactivated (TTL expired, no holders)' : ''}`) console.log(`[price] #${tag} got 0 posts (zeroCount=${newZeroCount})${shouldDeactivate ? ' — deactivated (TTL expired, no holders)' : ''}`)
return return
} }
// If TTL expired and no holders, deactivate instead of updating // If TTL expired and no holders, record final price then deactivate
if (ttlExpired && ownerCount === 0) { if (ttlExpired && ownerCount === 0) {
await prisma.hashtag.update({ const finalPrice = calcPrice(postsPerHour)
await prisma.$transaction([
prisma.hashtag.update({
where: { id: hashtagId }, where: { id: hashtagId },
data: { isActive: false, lastUpdated: new Date() }, data: { currentPrice: finalPrice, isActive: false, lastUpdated: new Date() },
}) }),
console.log(`[price] #${tag} deactivated — TTL expired, no holders`) prisma.priceHistory.create({
data: { hashtagId, price: finalPrice, postsPerHour },
}),
])
console.log(`[price] #${tag} deactivated — TTL expired, no holders (final price $${finalPrice.toFixed(2)})`)
return return
} }