mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 16:40:41 +00:00
fix: update check_usage_ to only consider past month usage (#1209)
This change modifies the SQL query in check_usage_ to only consider AI usage from the past month when checking against limits, rather than all historical usage. ai: true
This commit is contained in:
@@ -662,11 +662,15 @@ class AIChatService extends BaseService {
|
||||
const reading = await svc_permission.scan(actor, `paid-services:ai-chat`);
|
||||
const options = PermissionUtil.reading_to_options(reading);
|
||||
|
||||
// Query current ai usage in terms of cost
|
||||
// Query current ai usage in terms of cost (only from the past month)
|
||||
const oneMonthAgo = new Date();
|
||||
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
|
||||
const oneMonthAgoStr = oneMonthAgo.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
const [row] = await this.db.read(
|
||||
'SELECT SUM(`cost`) AS sum FROM `ai_usage` ' +
|
||||
'WHERE `user_id` = ?',
|
||||
[actor.type.user.id]
|
||||
'WHERE `user_id` = ? AND `created_at` >= ?',
|
||||
[actor.type.user.id, oneMonthAgoStr]
|
||||
);
|
||||
|
||||
const cost_used = row?.sum || 0;
|
||||
|
||||
Reference in New Issue
Block a user