Compare commits

...

2 Commits

14 changed files with 108 additions and 46 deletions

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.16.44](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.43...@standardnotes/home-server@1.16.44) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.43](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.42...@standardnotes/home-server@1.16.43) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/home-server",
"version": "1.16.43",
"version": "1.16.44",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.43.1](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.43.0...@standardnotes/revisions-server@1.43.1) (2023-10-10)
### Bug Fixes
* transition logs to be more verbose ([036317e](https://github.com/standardnotes/server/commit/036317e33347f121fa799cbd409f85759798369d))
# [1.43.0](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.42.3...@standardnotes/revisions-server@1.43.0) (2023-10-10)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/revisions-server",
"version": "1.43.0",
"version": "1.43.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -13,5 +13,6 @@ export interface RevisionRepositoryInterface {
updateUserUuid(itemUuid: Uuid, userUuid: Uuid): Promise<void>
findByUserUuid(dto: { userUuid: Uuid; offset?: number; limit?: number }): Promise<Array<Revision>>
insert(revision: Revision): Promise<boolean>
update(revision: Revision): Promise<boolean>
clearSharedVaultAndKeySystemAssociations(dto: { itemUuid?: Uuid; sharedVaultUuid: Uuid }): Promise<void>
}

View File

@@ -115,8 +115,10 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
this.logger.info(`[${userUuid.value}] Total revisions count for user: ${totalRevisionsCountForUser}`)
const totalPages = Math.ceil(totalRevisionsCountForUser / this.pageSize)
this.logger.info(`[${userUuid.value}] Total pages: ${totalPages}`)
let insertedRevisionsCount = 0
let skippedRevisionsCount = 0
let insertedCount = 0
let newerCount = 0
let identicalCount = 0
let updatedCount = 0
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
if (isPageInEvery10Percent) {
@@ -126,7 +128,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
)}% completed`,
)
this.logger.info(
`[${userUuid.value}] Inserted ${insertedRevisionsCount} revisions so far. Skipped ${skippedRevisionsCount} revisions so far.`,
`[${userUuid.value}] Inserted ${insertedCount} revisions so far. Skipped ${newerCount} revisions because they were newer in primary database. Skipped ${identicalCount} revisions because they were identical in primary and secondary database. Updated ${updatedCount} revisions because they were older in primary database.`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
}
@@ -151,41 +153,31 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
[],
)
if (revisionInPrimary !== null) {
if (!revisionInPrimary) {
await this.primaryRevisionsRepository.insert(revision)
insertedCount++
} else {
if (revisionInPrimary.props.dates.updatedAt > revision.props.dates.updatedAt) {
this.logger.info(
`[${
userUuid.value
}] Revision ${revision.id.toString()} is older in secondary than revision in primary database`,
)
skippedRevisionsCount++
newerCount++
continue
}
if (revisionInPrimary.isIdenticalTo(revision)) {
skippedRevisionsCount++
identicalCount++
continue
}
this.logger.info(
`[${userUuid.value}] Removing revision ${revision.id.toString()} in primary database: ${JSON.stringify(
revisionInPrimary,
)} as it is not identical to revision in secondary database: ${JSON.stringify(revision)}`,
)
await this.primaryRevisionsRepository.update(revision)
await this.primaryRevisionsRepository.removeOneByUuid(
Uuid.create(revisionInPrimary.id.toString()).getValue(),
revisionInPrimary.props.userUuid as Uuid,
)
await this.allowForPrimaryDatabaseToCatchUp()
}
const didSave = await this.primaryRevisionsRepository.insert(revision)
if (!didSave) {
this.logger.error(`Failed to save revision ${revision.id.toString()} to primary database`)
} else {
insertedRevisionsCount++
updatedCount++
}
} catch (error) {
this.logger.error(
@@ -196,7 +188,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
}
this.logger.info(
`[${userUuid.value}] Inserted ${insertedRevisionsCount} revisions. Skipped ${skippedRevisionsCount} revisions.`,
`[${userUuid.value}] Inserted ${insertedCount} revisions. Skipped ${newerCount} revisions because they were newer in primary database. Skipped ${identicalCount} revisions because they were identical in primary and secondary database. Updated ${updatedCount} revisions because they were older in primary database.`,
)
return Result.ok()

View File

@@ -193,4 +193,14 @@ export class MongoDBRevisionRepository implements RevisionRepositoryInterface {
return insertResult.acknowledged
}
async update(revision: Revision): Promise<boolean> {
const persistence = this.revisionMapper.toProjection(revision)
const { _id, ...rest } = persistence
const updateResult = await this.mongoRepository.updateOne({ _id: _id }, { $set: rest })
return updateResult.acknowledged
}
}

View File

@@ -111,9 +111,19 @@ export class SQLLegacyRevisionRepository implements RevisionRepositoryInterface
}
async insert(revision: Revision): Promise<boolean> {
const SQLLegacyRevision = this.revisionMapper.toProjection(revision)
const projection = this.revisionMapper.toProjection(revision)
await this.ormRepository.insert(SQLLegacyRevision)
await this.ormRepository.insert(projection)
return true
}
async update(revision: Revision): Promise<boolean> {
const projection = this.revisionMapper.toProjection(revision)
const { uuid, ...rest } = projection
await this.ormRepository.update({ uuid: uuid }, rest)
return true
}

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.115.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.115.0...@standardnotes/syncing-server@1.115.1) (2023-10-10)
### Bug Fixes
* transition logs to be more verbose ([036317e](https://github.com/standardnotes/syncing-server-js/commit/036317e33347f121fa799cbd409f85759798369d))
# [1.115.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.114.3...@standardnotes/syncing-server@1.115.0) (2023-10-10)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.115.0",
"version": "1.115.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -18,6 +18,8 @@ export interface ItemRepositoryInterface {
remove(item: Item): Promise<void>
removeByUuid(uuid: Uuid): Promise<void>
save(item: Item): Promise<void>
insert(item: Item): Promise<void>
update(item: Item): Promise<void>
markItemsAsDeleted(itemUuids: Array<string>, updatedAtTimestamp: number): Promise<void>
updateContentSize(itemUuid: string, contentSize: number): Promise<void>
unassignFromSharedVault(sharedVaultUuid: Uuid): Promise<void>

View File

@@ -117,8 +117,10 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
this.logger.info(`[${userUuid.value}] Total items count for user: ${totalItemsCountForUser}`)
const totalPages = Math.ceil(totalItemsCountForUser / this.pageSize)
this.logger.info(`[${userUuid.value}] Total pages: ${totalPages}`)
let insertedItemsCount = 0
let skippedItemsCount = 0
let insertedCount = 0
let updatedCount = 0
let newerCount = 0
let identicalCount = 0
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
if (isPageInEvery10Percent) {
@@ -126,7 +128,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
`[${userUuid.value}] Migrating items for user: ${Math.round((currentPage / totalPages) * 100)}% completed`,
)
this.logger.info(
`[${userUuid.value}] Inserted items count: ${insertedItemsCount}. Skipped items count: ${skippedItemsCount}`,
`[${userUuid.value}] Inserted items count: ${insertedCount}. Newer items count: ${newerCount}. Identical items count: ${identicalCount}. Updated items count: ${updatedCount}`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
}
@@ -150,33 +152,29 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
try {
const itemInPrimary = await this.primaryItemRepository.findByUuid(item.uuid)
if (itemInPrimary !== null) {
if (!itemInPrimary) {
await this.primaryItemRepository.insert(item)
insertedCount++
} else {
if (itemInPrimary.props.timestamps.updatedAt > item.props.timestamps.updatedAt) {
this.logger.info(
`[${userUuid.value}] Item ${item.uuid.value} is older in secondary than item in primary database`,
)
skippedItemsCount++
newerCount++
continue
}
if (itemInPrimary.isIdenticalTo(item)) {
skippedItemsCount++
identicalCount++
continue
}
this.logger.info(
`[${userUuid.value}] Removing item ${item.uuid.value} in primary database as it is not identical to item in primary database`,
)
await this.primaryItemRepository.update(item)
await this.primaryItemRepository.removeByUuid(item.uuid)
await this.allowForPrimaryDatabaseToCatchUp()
updatedCount++
}
await this.primaryItemRepository.save(item)
insertedItemsCount++
} catch (error) {
this.logger.error(
`Errored when saving item ${item.uuid.value} to primary database: ${(error as Error).message}`,
@@ -186,7 +184,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
}
this.logger.info(
`[${userUuid.value}] Inserted items count: ${insertedItemsCount}. Skipped items count: ${skippedItemsCount}`,
`[${userUuid.value}] Inserted items count: ${insertedCount}. Newer items count: ${newerCount}. Identical items count: ${identicalCount}. Updated items count: ${updatedCount}`,
)
return Result.ok()

View File

@@ -184,6 +184,25 @@ export class MongoDBItemRepository implements ItemRepositoryInterface {
)
}
async insert(item: Item): Promise<void> {
const persistence = this.mapper.toProjection(item)
await this.mongoRepository.insertOne(persistence)
}
async update(item: Item): Promise<void> {
const persistence = this.mapper.toProjection(item)
const { _id, ...rest } = persistence
await this.mongoRepository.updateOne(
{ _id: _id },
{
$set: rest,
},
)
}
async markItemsAsDeleted(itemUuids: string[], updatedAtTimestamp: number): Promise<void> {
await this.mongoRepository.updateMany(
{ _id: { $in: itemUuids.map((uuid) => BSON.UUID.createFromHexString(uuid)) } },

View File

@@ -43,6 +43,20 @@ export class SQLLegacyItemRepository implements ItemRepositoryInterface {
await this.ormRepository.save(persistence)
}
async insert(item: Item): Promise<void> {
const projection = this.mapper.toProjection(item)
await this.ormRepository.insert(projection)
}
async update(item: Item): Promise<void> {
const projection = this.mapper.toProjection(item)
const { uuid, ...updateValues } = projection
await this.ormRepository.update({ uuid: uuid }, updateValues)
}
async remove(item: Item): Promise<void> {
await this.ormRepository.remove(this.mapper.toProjection(item))
}