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

PIMS-1803: Bulk upload API #2478

Merged
merged 24 commits into from
Jul 5, 2024
Merged

PIMS-1803: Bulk upload API #2478

merged 24 commits into from
Jul 5, 2024

Conversation

GrahamS-Quartech
Copy link
Contributor

@GrahamS-Quartech GrahamS-Quartech commented Jun 25, 2024

🎯 Summary

PIMS-1803

  • Adds a new endpoint that will accept a file using multer.
  • Endpoint will return a 200 OK response ASAP, but not until after forking a node worker thread that will handle the file.
  • The worker thread will attempt to bulk upsert the rows present in the spreadsheet using the SheetJS xlsx package.
  • Results are collected in a new import_result table, so make sure you run the migration.

Please check general business logic in properties services and see if it makes sense with your own understanding and the previous implementation in the .NET API.

Note that a rollback transaction is wrapping the upload process right now. I will remove this before merging this branch.

🔰 Checklist

  • I have read and agree with the following checklist and am following the guidelines in our Code of Conduct document.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation where required.
  • I have tested my changes to the best of my ability.
  • My changes generate no new warnings.

…s for importinb parcels, one using manual row iteration and another using the _to_json util
… processing then immediately return a status 200. Also, there is handling for deleting the uploaded file once the task finishes now.
…ndividual row failures do not make the entire upload fail. Results are collected into an array with action and reason for the action.
…ction types, and admin areas. Also modified the property save structure to not overwrite the existing CreatedBy data on update.
@GrahamS-Quartech GrahamS-Quartech marked this pull request as ready for review July 2, 2024 22:30
@GrahamS-Quartech GrahamS-Quartech changed the title PIMS-1803: Bulk upload api POC PIMS-1803: Bulk upload API Jul 2, 2024
Copy link
Collaborator

@dbarkowsky dbarkowsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where this is going. It seems like it's going to be really efficient compared to the old way of doing it.
Would like to have more information on the results though. I don't see how we could effectively identify which row caused the error. A row number would be good.
image

express-api/package.json Outdated Show resolved Hide resolved
@@ -22,6 +22,7 @@
"dependencies": {
"@bcgov/citz-imb-kc-css-api": "https://github.com/bcgov/citz-imb-kc-css-api/releases/download/v1.4.0/bcgov-citz-imb-kc-css-api-1.4.0.tgz",
"@bcgov/citz-imb-sso-express": "1.0.0-rc2",
"@types/multer": "^1.4.11",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@types/multer": "^1.4.11",
"@types/multer": "1.4.11",

Should also be in dev dependencies.

express-api/package.json Outdated Show resolved Hide resolved
existentParcel,
);
queuedParcels.push(parcelToUpsert);
results.push({ action: existentParcel ? 'updated' : 'inserted' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we push this success action here, could it still fail when the queuedParcels/Buildings goes to insert?
I'm thinking this might return false positives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well in theory, anything that would cause the parcelToUpsert object to be invalid would have already thrown an error inside the makeParcelUpsertObject function. But that's a good point, the insert could still fail for some unexpected reason when it actually makes the save call. I suppose this may be another reason the old API does everything one at a time, but in the ideal case where all rows from the spreadsheet contain new PIDs it's much faster to do batched insert. I'll have to think about this a bit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely like the batch better. Just wondering if there's a way to see which items failed in that batch insert, then update the results maybe.

@@ -27,6 +29,10 @@ router.route('/search/geo').get(activeUserCheck, catchErrors(getPropertiesForMap
router.route('/search/page').get(activeUserCheck, catchErrors(getPropertiesPaged));
router.route('/search/page/filter').post(activeUserCheck, catchErrors(getPropertiesPagedFilter));

const upload = multer({ dest: 'uploads/' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean it will keep a local copy of the file in the container? Or it's just temporary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does temporarily create a copy of the file in the container but propertiesController.ts:210 will attempt to destroy it before exiting after processing the file.

Copy link
Collaborator

@dbarkowsky dbarkowsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well. Appreciate the enhanced feedback.

@GrahamS-Quartech GrahamS-Quartech merged commit 5dc0017 into main Jul 5, 2024
4 of 5 checks passed
@GrahamS-Quartech GrahamS-Quartech deleted the PIMS-1803-BulkUploadAPI branch July 5, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants