Compare commits
No commits in common. "16fb74ec4b9fc61a222b600935eb70e3ea988938" and "b2ee15602857b322bf8d8355cea3713bee470c1e" have entirely different histories.
16fb74ec4b
...
b2ee156028
1 changed files with 2 additions and 26 deletions
|
@ -65,34 +65,9 @@ export default class tokenCount implements IQuota {
|
||||||
return this.createUserQuotaData(this.defaultQuota, usedUnits);
|
return this.createUserQuotaData(this.defaultQuota, usedUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to use proper query based on considerInputTokensAsHalf setting
|
|
||||||
* @param user The user to find nth usage
|
|
||||||
* @param requestTimestamp the timestamp of the request
|
|
||||||
* @param unitCount the unit count to check
|
|
||||||
* @returns promise of giving out the record
|
|
||||||
*/
|
|
||||||
findNthUsage(user: string, requestTimestamp: number, unitCount: number) {
|
findNthUsage(user: string, requestTimestamp: number, unitCount: number) {
|
||||||
if (this.considerInputTokensAsHalf)
|
if (this.considerInputTokensAsHalf)
|
||||||
return database.$queryRaw<Array<Usage & {usage: number}>>`
|
throw("Not implemented");
|
||||||
SELECT t1.*, (
|
|
||||||
SELECT
|
|
||||||
SUM(usageResponse + usageRequest/2) AS usage
|
|
||||||
FROM \`usage\`
|
|
||||||
WHERE
|
|
||||||
user = ${user} AND
|
|
||||||
timestamp >= ${requestTimestamp - this.lookback} AND
|
|
||||||
timestamp <= t1.timestamp
|
|
||||||
) as usage
|
|
||||||
FROM
|
|
||||||
\`usage\` AS t1
|
|
||||||
WHERE
|
|
||||||
user = ${user} AND
|
|
||||||
timestamp >= ${requestTimestamp - this.lookback} AND
|
|
||||||
usage >= ${unitCount}
|
|
||||||
ORDER BY timestamp ASC
|
|
||||||
LIMIT 1
|
|
||||||
`;
|
|
||||||
return database.$queryRaw<Array<Usage & {usage: bigint}>>`
|
return database.$queryRaw<Array<Usage & {usage: bigint}>>`
|
||||||
SELECT t1.*, (
|
SELECT t1.*, (
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -125,6 +100,7 @@ export default class tokenCount implements IQuota {
|
||||||
this.findNthUsage(userId, request.createdTimestamp, unitCount)
|
this.findNthUsage(userId, request.createdTimestamp, unitCount)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
console.log(renameMebecause);
|
||||||
return {
|
return {
|
||||||
...userQuota,
|
...userQuota,
|
||||||
recoveryTimestamp: (renameMebecause.at(0)?.timestamp.valueOf() ?? Infinity) + this.lookback,
|
recoveryTimestamp: (renameMebecause.at(0)?.timestamp.valueOf() ?? Infinity) + this.lookback,
|
||||||
|
|
Loading…
Reference in a new issue