try to fix active stocks losing price updates
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s
This commit is contained in:
+27
-14
@@ -144,25 +144,38 @@ const priceWorker = new Worker(
|
||||
}
|
||||
|
||||
const shouldDeactivate = ttlExpired && ownerCount === 0
|
||||
await prisma.hashtag.update({
|
||||
where: { id: hashtagId },
|
||||
data: {
|
||||
zeroCount: newZeroCount,
|
||||
isActive: shouldDeactivate ? false : hashtag.isActive,
|
||||
lastUpdated: new Date(),
|
||||
},
|
||||
})
|
||||
const floorPrice = calcPrice(0)
|
||||
await prisma.$transaction([
|
||||
prisma.hashtag.update({
|
||||
where: { id: hashtagId },
|
||||
data: {
|
||||
zeroCount: newZeroCount,
|
||||
isActive: shouldDeactivate ? false : hashtag.isActive,
|
||||
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)' : ''}`)
|
||||
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) {
|
||||
await prisma.hashtag.update({
|
||||
where: { id: hashtagId },
|
||||
data: { isActive: false, lastUpdated: new Date() },
|
||||
})
|
||||
console.log(`[price] #${tag} deactivated — TTL expired, no holders`)
|
||||
const finalPrice = calcPrice(postsPerHour)
|
||||
await prisma.$transaction([
|
||||
prisma.hashtag.update({
|
||||
where: { id: hashtagId },
|
||||
data: { currentPrice: finalPrice, isActive: false, lastUpdated: new Date() },
|
||||
}),
|
||||
prisma.priceHistory.create({
|
||||
data: { hashtagId, price: finalPrice, postsPerHour },
|
||||
}),
|
||||
])
|
||||
console.log(`[price] #${tag} deactivated — TTL expired, no holders (final price $${finalPrice.toFixed(2)})`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user