fix: recipe/storage tier limits are lifetime totals, not monthly (v0.58.0)
Recipe count and storage usage shared the monthly user_usage bucket with AI calls, so both incorrectly reset every month even though nothing was deleted. Only AI calls should be monthly. Recipe count and storage are now derived live from real data (recipes, recipe/review photos, avatar) instead of a counter — deleting a photo or recipe is itself the "decrement", no extra wiring needed. Storage size is tracked per-row (recipePhotos.sizeMb, ratings.photoSizeMb, users.avatarSizeMb) and threaded through presign -> upload -> save. Also fixes avatar removal silently no-oping (client sent a field the PATCH schema didn't recognize). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,9 +19,12 @@ export async function PATCH(req: NextRequest, { params }: RouteContext) {
|
||||
const { id } = await params;
|
||||
const month = currentMonth();
|
||||
|
||||
// Only aiCallsUsed is a resettable monthly counter — recipe count and
|
||||
// storage usage are lifetime totals derived live from real data (recipes,
|
||||
// photos, avatar), so there's nothing to reset there.
|
||||
const [updated] = await db
|
||||
.update(userUsage)
|
||||
.set({ aiCallsUsed: 0, recipeCount: 0, storageUsedMb: 0 })
|
||||
.set({ aiCallsUsed: 0 })
|
||||
.where(and(eq(userUsage.userId, id), eq(userUsage.month, month)))
|
||||
.returning();
|
||||
|
||||
@@ -35,5 +38,5 @@ export async function PATCH(req: NextRequest, { params }: RouteContext) {
|
||||
createdAt: new Date(),
|
||||
});
|
||||
|
||||
return NextResponse.json({ usage: updated ?? { userId: id, month, aiCallsUsed: 0, recipeCount: 0, storageUsedMb: 0 } });
|
||||
return NextResponse.json({ usage: updated ?? { userId: id, month, aiCallsUsed: 0 } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user