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

feat(web): delete all assets associated with stack on asset delete #14618

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions web/src/lib/components/asset-viewer/actions/delete-action.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { showDeleteModal } from '$lib/stores/preferences.store';
import { featureFlags } from '$lib/stores/server-config.store';
import { handleError } from '$lib/utils/handle-error';
import { deleteAssets, type AssetResponseDto } from '@immich/sdk';
import { deleteStack, getStack, deleteAssets, type AssetResponseDto } from '@immich/sdk';
import { mdiDeleteForeverOutline, mdiDeleteOutline } from '@mdi/js';
import { t } from 'svelte-i18n';
import type { OnAction } from './action';
Expand Down Expand Up @@ -41,7 +41,16 @@

const trashAsset = async () => {
try {
await deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
if (asset.stack) {
const { assets } = await getStack({ id: asset.stack.id });
const assetIds = assets.map((asset) => asset.id);

await deleteStack({ id: asset.stack.id });
await deleteAssets({ assetBulkDeleteDto: { ids: assetIds } });
} else {
await deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
}

onAction({ type: AssetAction.TRASH, asset });

notificationController.show({
Expand Down
35 changes: 33 additions & 2 deletions web/src/lib/components/photos-page/actions/delete-assets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import { type OnDelete, deleteAssets } from '$lib/utils/actions';
import DeleteAssetDialog from '../delete-asset-dialog.svelte';
import { t } from 'svelte-i18n';
import { deleteStacks, getStack } from '@immich/sdk';

import { handleError } from '$lib/utils/handle-error';

interface Props {
onAssetDelete: OnDelete;
Expand Down Expand Up @@ -34,8 +37,36 @@

const handleDelete = async () => {
loading = true;
const ids = [...getOwnedAssets()].map((a) => a.id);
await deleteAssets(force, onAssetDelete, ids);
const ownedAssets = [...getOwnedAssets()];
Copy link
Contributor

Choose a reason for hiding this comment

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

If you have 100,000 assets, will this populate 100,000 element array here?


try {
const stackIds: string[] = [];
const pendingAssetIds: Array<Promise<string[]>> = [];
const assetIds: string[] = [];
for (const asset of ownedAssets) {
let stackId = asset.stack?.id;

if (stackId) {
stackIds.push(stackId);

const assetIds = getStack({ id: stackId }).then((stack) => stack.assets.map((asset) => asset.id));
pendingAssetIds.push(assetIds);
} else {
assetIds.push(asset.id);
}
}

let fetchedAssetIds = await Promise.all(pendingAssetIds);
const ids = assetIds.concat(...fetchedAssetIds.flat());

if (stackIds.length > 0) {
await deleteStacks({ bulkIdsDto: { ids: stackIds } });
}
await deleteAssets(force, onAssetDelete, ids);
} catch (error) {
handleError(error, $t('errors.unable_to_delete_assets'));
}

clearSelect();
isShowConfirmation = false;
loading = false;
Expand Down
Loading