fix(syncing-server): select fields in query for revisions

This commit is contained in:
Karol Sójko
2022-12-15 07:28:43 +01:00
parent 6df42fb0d5
commit ce53c459e6
3 changed files with 8 additions and 6 deletions
+5 -3
View File
@@ -27,7 +27,7 @@ const fixRevisionsOwnership = async (
const itemsCount = await itemRepository.countAll({
createdBetween: [createdAfter, createdBefore],
selectString: 'item.uuid AS uuid, item.user_uuid AS userUuid',
selectFields: ['uuid', 'userUuid'],
contentType: [ContentType.Note, ContentType.File],
sortOrder: 'ASC',
sortBy: 'uuid',
@@ -39,16 +39,17 @@ const fixRevisionsOwnership = async (
const amountOfPages = Math.ceil(itemsCount / limit)
const tenPercentOfPages = Math.ceil(amountOfPages / 10)
let itemsProcessedCounter = 0
let itemsSkippedCounter = 0
for (let page = 1; page <= amountOfPages; page++) {
if (page % tenPercentOfPages === 0) {
logger.info(
`Processing page ${page} of ${amountOfPages} items between ${createdAfter.toISOString()} and ${createdBefore.toISOString()}. Processed successfully ${itemsProcessedCounter} items.`,
`Processing page ${page} of ${amountOfPages} items between ${createdAfter.toISOString()} and ${createdBefore.toISOString()}. Processed successfully ${itemsProcessedCounter} items. Skipped ${itemsSkippedCounter} items.`,
)
}
const items = await itemRepository.findAll({
createdBetween: [createdAfter, createdBefore],
selectString: 'item.uuid AS uuid, item.user_uuid AS userUuid',
selectFields: ['uuid', 'userUuid'],
contentType: [ContentType.Note, ContentType.File],
offset: (page - 1) * limit,
limit,
@@ -58,6 +59,7 @@ const fixRevisionsOwnership = async (
for (const item of items) {
if (!item.userUuid || !item.uuid) {
itemsSkippedCounter++
continue
}
@@ -10,5 +10,5 @@ export type ItemQuery = {
offset?: number
limit?: number
createdBetween?: Date[]
selectString?: string
selectFields?: string[]
}
@@ -135,8 +135,8 @@ export class MySQLItemRepository implements ItemRepositoryInterface {
queryBuilder.orderBy(`item.${query.sortBy}`, query.sortOrder)
}
if (query.selectString !== undefined) {
queryBuilder.select(query.selectString)
if (query.selectFields !== undefined) {
queryBuilder.select(query.selectFields)
}
if (query.userUuid !== undefined) {
queryBuilder.where('item.user_uuid = :userUuid', { userUuid: query.userUuid })