fix(revisions): info logs on total revisions transitioned count

This commit is contained in:
Karol Sójko 2023-09-01 08:21:41 +02:00
parent 1bef1279e6
commit e5c118c262
No known key found for this signature in database
GPG key ID: C2F813669419D05F

View file

@ -74,6 +74,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
private async migrateRevisionsForUser(userUuid: Uuid): Promise<Result<void>> {
try {
const totalRevisionsCountForUser = await this.primaryRevisionsRepository.countByUserUuid(userUuid)
let totalRevisionsCountTransitionedToSecondary = 0
const pageSize = 1
const totalPages = Math.ceil(totalRevisionsCountForUser / pageSize)
for (let currentPage = 1; currentPage <= totalPages; currentPage++) {
@ -91,6 +92,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
if (!didSave) {
return Result.fail(`Failed to save revision ${revision.id.toString()} to secondary database`)
}
totalRevisionsCountTransitionedToSecondary++
} catch (error) {
return Result.fail(
`Errored when saving revision ${revision.id.toString()} to secondary database: ${
@ -101,6 +103,8 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
}
}
this.logger.info(`Transitioned ${totalRevisionsCountTransitionedToSecondary} revisions to secondary database`)
return Result.ok()
} catch (error) {
return Result.fail(`Errored when migrating revisions for user ${userUuid.value}: ${(error as Error).message}`)