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
|
const shouldDeactivate = ttlExpired && ownerCount === 0
|
||||||
await prisma.hashtag.update({
|
const floorPrice = calcPrice(0)
|
||||||
where: { id: hashtagId },
|
await prisma.$transaction([
|
||||||
data: {
|
prisma.hashtag.update({
|
||||||
zeroCount: newZeroCount,
|
where: { id: hashtagId },
|
||||||
isActive: shouldDeactivate ? false : hashtag.isActive,
|
data: {
|
||||||
lastUpdated: new Date(),
|
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)' : ''}`)
|
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)
|
||||||
where: { id: hashtagId },
|
await prisma.$transaction([
|
||||||
data: { isActive: false, lastUpdated: new Date() },
|
prisma.hashtag.update({
|
||||||
})
|
where: { id: hashtagId },
|
||||||
console.log(`[price] #${tag} deactivated — TTL expired, no holders`)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user