-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from tnc-ca-geo/feature/227-bulk_image_deletion
Bulk Image Deletion Task
- Loading branch information
Showing
10 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default /* GraphQL */ ` | ||
input DeleteImagesByFilterInput { | ||
filters: FiltersInput! | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default /* GraphQL */ ` | ||
input DeleteImagesByFilterTaskInput { | ||
filters: FiltersInput! | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { type User } from '../api/auth/authorization.js'; | ||
import { ImageModel } from '../api/db/models/Image.js'; | ||
import { TaskInput } from '../api/db/models/Task.js'; | ||
import type * as gql from '../@types/graphql.js'; | ||
|
||
export async function DeleteImagesByFilter(task: TaskInput<gql.DeleteImagesByFilterTaskInput>) { | ||
/** | ||
* Deletes images that match the inputted filters in batches of 100. | ||
* This is used by the frontend to delete all images currently shown. | ||
* * @param {Object} input | ||
* * @param {gql.FiltersInput} input.config.filters | ||
*/ | ||
const context = { user: { is_superuser: true, curr_project: task.projectId } as User }; | ||
let images = await ImageModel.queryByFilter( | ||
{ filters: task.config.filters, limit: 100 }, | ||
context, | ||
); | ||
while (images.results.length > 0) { | ||
const batch = images.results.map((image) => image._id); | ||
await ImageModel.deleteImages({ imageIds: batch }, context); | ||
if (images.hasNext) { | ||
images = await ImageModel.queryByFilter( | ||
{ filters: task.config.filters, limit: 100, next: images.next }, | ||
context, | ||
); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return { filters: task.config.filters }; | ||
} | ||
|
||
export async function DeleteImages(task: TaskInput<gql.DeleteImagesInput>) { | ||
/** | ||
* Deletes a list of images by their IDs in batches of 100. | ||
* This is used by the frontend when the user is selecting more than 100 images to delete to delete at once. | ||
* * @param {Object} input | ||
* * @param {String[]} input.config.imageIds | ||
*/ | ||
const context = { user: { is_superuser: true, curr_project: task.projectId } as User }; | ||
const imagesToDelete = task.config.imageIds?.slice() ?? []; | ||
while (imagesToDelete.length > 0) { | ||
const batch = imagesToDelete.splice(0, 100); | ||
await ImageModel.deleteImages({ imageIds: batch }, context); | ||
} | ||
return { imageIds: task.config.imageIds }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters