Skip to content

Commit

Permalink
[fga] run job more often with smaller chunks (#18675)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge authored Sep 7, 2023
1 parent 3a07121 commit e5932aa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions components/server/src/authorization/relationship-updater-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RelationshipUpdateJob implements Job {
) {}

public name = "relationship-update-job";
public frequencyMs = 1000 * 60 * 60 * 1; // 1h
public frequencyMs = 1000 * 60 * 3; // 3m

public async run(): Promise<void> {
try {
Expand All @@ -31,24 +31,26 @@ export class RelationshipUpdateJob implements Job {
additionalData->"$.fgaRelationshipsVersion" IS NULL) AND
markedDeleted = 0
ORDER BY _lastModified DESC
LIMIT 1000;`);
LIMIT 50;`);
const now = Date.now();
let migrated = 0;
for (const result of results) {
const user = await this.userDB.findUserById(result.id);
if (!user) {
continue;
}
try {
await this.relationshipUpdater.migrate(user);
const resultingUser = await this.relationshipUpdater.migrate(user);
if (resultingUser.additionalData?.fgaRelationshipsVersion === RelationshipUpdater.version) {
migrated++;
}
} catch (error) {
log.error(RelationshipUpdateJob.name + ": error running relationship update job", error);
log.error(this.name + ": error running relationship update job", error);
}
}
log.info(
RelationshipUpdateJob.name + ": updated " + results.length + " users in " + (Date.now() - now) + "ms",
);
log.info(this.name + ": updated " + migrated + " users in " + (Date.now() - now) + "ms");
} catch (error) {
log.error(RelationshipUpdateJob.name + ": error running relationship update job", error);
log.error(this.name + ": error running relationship update job", error);
}
}
}

0 comments on commit e5932aa

Please sign in to comment.