Skip to content

Commit

Permalink
fix set status to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed Sep 18, 2024
1 parent 60b512e commit 6f975a0
Showing 1 changed file with 54 additions and 43 deletions.
97 changes: 54 additions & 43 deletions packages/apollo-collaboration-server/src/changes/changes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ import { MessagesGateway } from '../messages/messages.gateway'
import { PluginsService } from '../plugins/plugins.service'
import { FindChangeDto } from './dto/find-change.dto'

const STATUS_ZERO_CHANGE_TYPES = new Set([
'AddAssemblyAndFeaturesFromFileChange',
'AddAssemblyFromExternalChange',
'AddAssemblyFromFileChange',
'AddFeaturesFromFileChange',
'AddFeatureChange',
])

export class ChangesService {
constructor(
@InjectModel(Feature.name)
Expand Down Expand Up @@ -158,51 +166,54 @@ export class ChangesService {
)
}
})
this.logger.debug?.('*** TEMPORARY DATA INSERTTED ***')
// Set "temporary document" -status --> "valid" -status i.e. (-1 --> 0)
await this.featureModel.db.transaction(async () => {
this.logger.debug(
'Updates "temporary document" -status --> "valid" -status',
)
try {
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
await this.refSeqChunkModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.featureModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.assemblyModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.refSeqModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
} catch (error) {
// Clean up old "temporary document" -documents

if (STATUS_ZERO_CHANGE_TYPES.has(change.typeName)) {
this.logger.debug?.('*** TEMPORARY DATA INSERTTED ***')
// Set "temporary document" -status --> "valid" -status i.e. (-1 --> 0)
await this.featureModel.db.transaction(async () => {
this.logger.debug(
'*** UPDATE STATUS EXCEPTION - Start to clean up old temporary documents...',
'Updates "temporary document" -status --> "valid" -status',
)
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
await this.assemblyModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.featureModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.refSeqModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.refSeqChunkModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
throw new UnprocessableEntityException(String(error))
}
})
try {
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
await this.refSeqChunkModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.featureModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.assemblyModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
await this.refSeqModel.updateMany(
{ $and: [{ status: -1, user: uniqUserId }] },
{ $set: { status: 0 } },
)
} catch (error) {
// Clean up old "temporary document" -documents
this.logger.debug(
'*** UPDATE STATUS EXCEPTION - Start to clean up old temporary documents...',
)
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
await this.assemblyModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.featureModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.refSeqModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
await this.refSeqChunkModel.deleteMany({
$and: [{ status: -1, user: uniqUserId }],
})
throw new UnprocessableEntityException(String(error))
}
})
}

this.logger.debug?.(`CHANGE DOC: ${JSON.stringify(changeDoc)}`)
if (!changeDoc) {
Expand Down

0 comments on commit 6f975a0

Please sign in to comment.