perf: make app entries more scalable, avoid writing global entries since its just puter itself and isn't relevant (#2233)
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled

This commit is contained in:
Daniel Salazar
2025-12-30 19:26:46 -08:00
committed by GitHub
parent 58c8ec7f43
commit aafdec9b81
@@ -14,7 +14,7 @@ import { DynamoKVStore } from '../repositories/DynamoKVStore/DynamoKVStore.js';
export class MeteringService {
static GLOBAL_SHARD_COUNT = 1000; // number of global usage shards to spread writes across
static APP_SHARD_COUNT = 100; // number of app usage shards to spread writes across
static APP_SHARD_COUNT = 1000; // number of app usage shards to spread writes across
#kvStore: DynamoKVStore;
#superUserService: SUService;
#alarmService: AlarmService;
@@ -125,13 +125,15 @@ export class MeteringService {
console.warn('Failed to increment aux usage data \'actorAppUsageKey\' with error: ', e);
});
const appUsageKey = this.#generateAppUsageKey(appId, currentMonth);
this.#kvStore.incr({
key: appUsageKey,
pathAndAmountMap,
}).catch((e: Error) => {
console.warn('Failed to increment aux usage data \'appUsageKey\' with error: ', e);
});
if ( appId !== GLOBAL_APP_KEY ) {
const appUsageKey = this.#generateAppUsageKey(appId, currentMonth);
this.#kvStore.incr({
key: appUsageKey,
pathAndAmountMap,
}).catch((e: Error) => {
console.warn('Failed to increment aux usage data \'appUsageKey\' with error: ', e);
});
}
const actorAppTotalsKey = `${METRICS_PREFIX}:actor:${userId}:apps:${currentMonth}`;
this.#kvStore.incr({