Spaces:
Build error
Build error
fix: race condition while logging chargeAmount
Browse files
backend/functions/src/cloud-functions/crawler.ts
CHANGED
|
@@ -425,9 +425,7 @@ ${this.content}
|
|
| 425 |
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
| 426 |
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
| 427 |
});
|
| 428 |
-
apiRoll.
|
| 429 |
-
chargeAmount,
|
| 430 |
-
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
| 431 |
}
|
| 432 |
});
|
| 433 |
} else if (ctx.req.ip) {
|
|
@@ -724,7 +722,7 @@ ${this.content}
|
|
| 724 |
}
|
| 725 |
}
|
| 726 |
|
| 727 |
-
getChargeAmount(formatted:
|
| 728 |
if (!formatted) {
|
| 729 |
return undefined;
|
| 730 |
}
|
|
@@ -735,7 +733,7 @@ ${this.content}
|
|
| 735 |
return estimateToken(textContent);
|
| 736 |
}
|
| 737 |
|
| 738 |
-
const imageContent = formatted.screenshotUrl || formatted?.screenshot;
|
| 739 |
|
| 740 |
if (imageContent) {
|
| 741 |
// OpenAI image token count for 1024x1024 image
|
|
|
|
| 425 |
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
| 426 |
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
| 427 |
});
|
| 428 |
+
apiRoll.chargeAmount = chargeAmount;
|
|
|
|
|
|
|
| 429 |
}
|
| 430 |
});
|
| 431 |
} else if (ctx.req.ip) {
|
|
|
|
| 722 |
}
|
| 723 |
}
|
| 724 |
|
| 725 |
+
getChargeAmount(formatted: FormattedPage) {
|
| 726 |
if (!formatted) {
|
| 727 |
return undefined;
|
| 728 |
}
|
|
|
|
| 733 |
return estimateToken(textContent);
|
| 734 |
}
|
| 735 |
|
| 736 |
+
const imageContent = formatted.screenshotUrl || (formatted as any)?.screenshot;
|
| 737 |
|
| 738 |
if (imageContent) {
|
| 739 |
// OpenAI image token count for 1024x1024 image
|
backend/functions/src/cloud-functions/searcher.ts
CHANGED
|
@@ -169,9 +169,7 @@ export class SearcherHost extends RPCHost {
|
|
| 169 |
auth.reportUsage(chargeAmount, 'reader-search').catch((err) => {
|
| 170 |
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
| 171 |
});
|
| 172 |
-
apiRoll.
|
| 173 |
-
chargeAmount,
|
| 174 |
-
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
| 175 |
}
|
| 176 |
});
|
| 177 |
} else if (ctx.req.ip) {
|
|
@@ -184,9 +182,7 @@ export class SearcherHost extends RPCHost {
|
|
| 184 |
);
|
| 185 |
rpcReflect.finally(() => {
|
| 186 |
if (chargeAmount) {
|
| 187 |
-
apiRoll.
|
| 188 |
-
chargeAmount,
|
| 189 |
-
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
| 190 |
}
|
| 191 |
});
|
| 192 |
}
|
|
@@ -415,7 +411,7 @@ ${this.content}
|
|
| 415 |
return resultArray;
|
| 416 |
}
|
| 417 |
|
| 418 |
-
getChargeAmount(formatted:
|
| 419 |
return _.sum(
|
| 420 |
formatted.map((x) => this.crawler.getChargeAmount(x) || 0)
|
| 421 |
);
|
|
|
|
| 169 |
auth.reportUsage(chargeAmount, 'reader-search').catch((err) => {
|
| 170 |
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
| 171 |
});
|
| 172 |
+
apiRoll.chargeAmount = chargeAmount;
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
});
|
| 175 |
} else if (ctx.req.ip) {
|
|
|
|
| 182 |
);
|
| 183 |
rpcReflect.finally(() => {
|
| 184 |
if (chargeAmount) {
|
| 185 |
+
apiRoll.chargeAmount = chargeAmount;
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
});
|
| 188 |
}
|
|
|
|
| 411 |
return resultArray;
|
| 412 |
}
|
| 413 |
|
| 414 |
+
getChargeAmount(formatted: FormattedPage[]) {
|
| 415 |
return _.sum(
|
| 416 |
formatted.map((x) => this.crawler.getChargeAmount(x) || 0)
|
| 417 |
);
|
thinapps-shared
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
Subproject commit
|
|
|
|
| 1 |
+
Subproject commit fc3545e3a7ae27968e69f351f109d3ffb535f963
|