mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 11:42:32 +08:00
fix: race condition while logging chargeAmount
This commit is contained in:
parent
6f4819bc49
commit
8b0916f858
|
@ -425,9 +425,7 @@ ${this.content}
|
|||
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
||||
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
||||
});
|
||||
apiRoll._ref?.set({
|
||||
chargeAmount,
|
||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
||||
apiRoll.chargeAmount = chargeAmount;
|
||||
}
|
||||
});
|
||||
} else if (ctx.req.ip) {
|
||||
|
@ -724,7 +722,7 @@ ${this.content}
|
|||
}
|
||||
}
|
||||
|
||||
getChargeAmount(formatted: { [k: string]: any; }) {
|
||||
getChargeAmount(formatted: FormattedPage) {
|
||||
if (!formatted) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -735,7 +733,7 @@ ${this.content}
|
|||
return estimateToken(textContent);
|
||||
}
|
||||
|
||||
const imageContent = formatted.screenshotUrl || formatted?.screenshot;
|
||||
const imageContent = formatted.screenshotUrl || (formatted as any)?.screenshot;
|
||||
|
||||
if (imageContent) {
|
||||
// OpenAI image token count for 1024x1024 image
|
||||
|
|
|
@ -169,9 +169,7 @@ export class SearcherHost extends RPCHost {
|
|||
auth.reportUsage(chargeAmount, 'reader-search').catch((err) => {
|
||||
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
||||
});
|
||||
apiRoll._ref?.set({
|
||||
chargeAmount,
|
||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
||||
apiRoll.chargeAmount = chargeAmount;
|
||||
}
|
||||
});
|
||||
} else if (ctx.req.ip) {
|
||||
|
@ -184,9 +182,7 @@ export class SearcherHost extends RPCHost {
|
|||
);
|
||||
rpcReflect.finally(() => {
|
||||
if (chargeAmount) {
|
||||
apiRoll._ref?.set({
|
||||
chargeAmount,
|
||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
||||
apiRoll.chargeAmount = chargeAmount;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -415,7 +411,7 @@ ${this.content}
|
|||
return resultArray;
|
||||
}
|
||||
|
||||
getChargeAmount(formatted: any[]) {
|
||||
getChargeAmount(formatted: FormattedPage[]) {
|
||||
return _.sum(
|
||||
formatted.map((x) => this.crawler.getChargeAmount(x) || 0)
|
||||
);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2f2cdcff7b2738be33ee5aca858ef2d65eba29ed
|
||||
Subproject commit fc3545e3a7ae27968e69f351f109d3ffb535f963
|
Loading…
Reference in New Issue
Block a user