-
Notifications
You must be signed in to change notification settings - Fork 8
records import: add missing nodes #4120
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
base: master
Are you sure you want to change the base?
Changes from all commits
fdaeb2e
84b5729
7dd4f18
4be526f
7223f75
98b3dd7
e0f22aa
a30e2f2
97b1a74
9ffbd3b
dc10a59
888232a
8320273
d5bcb40
ed23305
58ffe06
3bbdfed
b836307
15dff03
2dfef0d
733f889
ee742de
a50dce8
f4a22ec
4f279af
363a527
2a6c878
51ad730
87d276c
9b4f2f4
9dea4ad
785913c
f5aea5f
36fb71f
eb197fc
7a60bcd
e140886
97fed6c
bb098fa
db29a90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,20 +11,30 @@ import * as Validation from '@core/validation/validation' | |
|
|
||
| import BatchPersister from '@server/db/batchPersister' | ||
| import Job from '@server/job/job' | ||
| import { RdbUpdatesBatchPersister } from '@server/modules/record/manager/RdbUpdatesBatchPersister' | ||
|
|
||
| import * as SurveyManager from '../manager/surveyManager' | ||
| import * as RecordManager from '../../record/manager/recordManager' | ||
|
|
||
| export default class RecordCheckJob extends Job { | ||
| constructor(params) { | ||
| super(RecordCheckJob.type, params) | ||
| } | ||
|
|
||
| async onStart() { | ||
| await super.onStart() | ||
| const { surveyId, tx, user } = this | ||
|
|
||
| this.surveyAndNodeDefsByCycle = {} // Cache of surveys and updated node defs by cycle | ||
| this.nodesBatchInserter = new BatchPersister(this.nodesBatchInsertHandler.bind(this), 2500) | ||
| this.nodesBatchUpdater = new BatchPersister(this.nodesBatchUpdateHandler.bind(this), 2500) | ||
| this.rdbUpdatesBatchPersister = new RdbUpdatesBatchPersister({ user, surveyId, tx }) | ||
| } | ||
|
|
||
| async execute() { | ||
| const recordsUuidAndCycle = await RecordManager.fetchRecordsUuidAndCycle({ surveyId: this.surveyId }, this.tx) | ||
| const { surveyId, tx, context } = this | ||
| const { recordUuidsIncluded = null } = context | ||
| const recordsUuidAndCycle = await RecordManager.fetchRecordsUuidAndCycle({ surveyId, recordUuidsIncluded }, tx) | ||
|
|
||
| this.total = R.length(recordsUuidAndCycle) | ||
|
|
||
|
|
@@ -118,7 +128,7 @@ export default class RecordCheckJob extends Job { | |
| const { context, surveyId, user, tx } = this | ||
| const { survey, nodeDefAddedUuids, nodeDefUpdatedUuids, nodeDefDeletedUuids, allNotDeletedNodeDefUuids } = | ||
| surveyAndNodeDefs | ||
| const { cleanupRecords } = context | ||
| const { cleanupRecords, updateRdb } = context | ||
|
|
||
| // this.logDebug(`checking record ${recordUuid}`) | ||
|
|
||
|
|
@@ -167,11 +177,16 @@ export default class RecordCheckJob extends Job { | |
| nodeDefAddedOrUpdatedUuidsUnique.add(Node.getNodeDefUuid(nodeInserted)) | ||
| } | ||
| const nodeDefAddedOrUpdatedUuids = Array.from(nodeDefAddedOrUpdatedUuidsUnique) | ||
| if (nodeDefAddedOrUpdatedUuids.length > 0) { | ||
|
|
||
| const nodeDefToCheckForDefaultValuesAndApplicabilityUuids = cleanupRecords | ||
| ? allNotDeletedNodeDefUuids | ||
| : nodeDefAddedOrUpdatedUuids | ||
|
|
||
| if (nodeDefToCheckForDefaultValuesAndApplicabilityUuids.length > 0) { | ||
| // this.logDebug('applying default values') | ||
| const { record: recordUpdate, nodes: nodesUpdatedDefaultValues = {} } = await _applyDefaultValuesAndApplicability( | ||
| survey, | ||
| nodeDefAddedOrUpdatedUuids, | ||
| nodeDefToCheckForDefaultValuesAndApplicabilityUuids, | ||
| record, | ||
| nodesInsertedByUuid, | ||
| tx | ||
|
|
@@ -208,6 +223,13 @@ export default class RecordCheckJob extends Job { | |
| this.tx | ||
| ) | ||
| } | ||
|
|
||
| if (updateRdb) { | ||
| await RecordManager.assocRefDataToNodes({ survey, nodes: allUpdatedNodesArray }, tx) | ||
| const { rdbUpdates } = RecordManager.generateRdbUpates({ survey, record, nodesArray: allUpdatedNodesArray }) | ||
| await this.rdbUpdatesBatchPersister.addItem(rdbUpdates) | ||
| } | ||
|
Comment on lines
+227
to
+231
|
||
|
|
||
| // this.logDebug('record check complete') | ||
| } | ||
|
|
||
|
|
@@ -251,6 +273,7 @@ export default class RecordCheckJob extends Job { | |
| super.beforeSuccess() | ||
| await this.nodesBatchInserter.flush(this.tx) | ||
| await this.nodesBatchUpdater.flush(this.tx) | ||
| await this.rdbUpdatesBatchPersister.flush() | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RecordCheckJobis now added to the mobile data import pipeline, but (unlike the Collect import / publish flows) this pipeline does not runSurveyRdbCreationJob/RecordsUniquenessValidationJobafterwards. SinceRecordCheckJobclears record-keys validation, this can leave imported/updated records without correct duplicate-keys validation. Either add a uniqueness validation step after the check (full or limited torecordUuidsIncluded), or adjustRecordCheckJobso it doesn’t clear record-keys validation when no follow-up uniqueness validation will run.