Skip to content

Commit

Permalink
adding docs and cleaing up nullish logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Nov 4, 2024
1 parent a51696c commit ccb2150
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/task/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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 },
Expand All @@ -26,11 +32,17 @@ export async function DeleteImagesByFilter(task: TaskInput<gql.DeleteImagesByFil
}

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 output = task.config.imageIds?.slice();
while (task.config.imageIds?.length && task.config.imageIds.length > 0) {
const batch = task.config.imageIds?.splice(0, 100);
const imagesToDelete = task.config.imageIds?.slice() ?? [];
while (imagesToDelete.length > 0) {
const batch = imagesToDelete.splice(0, 100);
await ImageModel.deleteImages({ imageIds: batch }, context);
}
return { imageIds: output };
return { imageIds: task.config.imageIds };
}
2 changes: 1 addition & 1 deletion src/task/stats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProjectModel } from '../api/db/models/Project.js';
import { buildPipeline, isImageReviewed, idMatch } from '../api/db/models/utils.js';
import { buildPipeline, idMatch } from '../api/db/models/utils.js';
import Image, { type ImageSchema } from '../api/db/schemas/Image.js';
import _ from 'lodash';
import { type TaskInput } from '../api/db/models/Task.js';
Expand Down

0 comments on commit ccb2150

Please sign in to comment.