|
@@ -112,7 +112,11 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
|
|
const totalRevisionsCountForUser = await (
|
|
const totalRevisionsCountForUser = await (
|
|
this.secondRevisionsRepository as RevisionRepositoryInterface
|
|
this.secondRevisionsRepository as RevisionRepositoryInterface
|
|
).countByUserUuid(userUuid)
|
|
).countByUserUuid(userUuid)
|
|
|
|
+ this.logger.info(`[${userUuid.value}] Total revisions count for user: ${totalRevisionsCountForUser}`)
|
|
const totalPages = Math.ceil(totalRevisionsCountForUser / this.pageSize)
|
|
const totalPages = Math.ceil(totalRevisionsCountForUser / this.pageSize)
|
|
|
|
+ this.logger.info(`[${userUuid.value}] Total pages: ${totalPages}`)
|
|
|
|
+ let insertedRevisionsCount = 0
|
|
|
|
+ let skippedRevisionsCount = 0
|
|
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
|
|
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
|
|
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
|
|
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
|
|
if (isPageInEvery10Percent) {
|
|
if (isPageInEvery10Percent) {
|
|
@@ -121,6 +125,9 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
|
|
(currentPage / totalPages) * 100,
|
|
(currentPage / totalPages) * 100,
|
|
)}% completed`,
|
|
)}% completed`,
|
|
)
|
|
)
|
|
|
|
+ this.logger.info(
|
|
|
|
+ `[${userUuid.value}] Inserted ${insertedRevisionsCount} revisions so far. Skipped ${skippedRevisionsCount} revisions so far.`,
|
|
|
|
+ )
|
|
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
|
|
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,10 +158,13 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
|
|
userUuid.value
|
|
userUuid.value
|
|
}] Revision ${revision.id.toString()} is older in secondary than revision in primary database`,
|
|
}] Revision ${revision.id.toString()} is older in secondary than revision in primary database`,
|
|
)
|
|
)
|
|
|
|
+ skippedRevisionsCount++
|
|
|
|
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if (revisionInPrimary.isIdenticalTo(revision)) {
|
|
if (revisionInPrimary.isIdenticalTo(revision)) {
|
|
|
|
+ skippedRevisionsCount++
|
|
|
|
+
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -174,6 +184,8 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
|
|
const didSave = await this.primaryRevisionsRepository.insert(revision)
|
|
const didSave = await this.primaryRevisionsRepository.insert(revision)
|
|
if (!didSave) {
|
|
if (!didSave) {
|
|
this.logger.error(`Failed to save revision ${revision.id.toString()} to primary database`)
|
|
this.logger.error(`Failed to save revision ${revision.id.toString()} to primary database`)
|
|
|
|
+ } else {
|
|
|
|
+ insertedRevisionsCount++
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.logger.error(
|
|
this.logger.error(
|
|
@@ -183,6 +195,10 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this.logger.info(
|
|
|
|
+ `[${userUuid.value}] Inserted ${insertedRevisionsCount} revisions. Skipped ${skippedRevisionsCount} revisions.`,
|
|
|
|
+ )
|
|
|
|
+
|
|
return Result.ok()
|
|
return Result.ok()
|
|
} catch (error) {
|
|
} catch (error) {
|
|
return Result.fail(`Errored when migrating revisions for user ${userUuid.value}: ${(error as Error).message}`)
|
|
return Result.fail(`Errored when migrating revisions for user ${userUuid.value}: ${(error as Error).message}`)
|