Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set status to 0 for relevant change types #443

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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