Skip to main content

Zombie Killer Worker

Cleans up orphaned database records and files that are no longer referenced by their parent entities.

Included in Base Preset

This plugin is part of the base preset and loaded automatically. Using the base preset is strongly recommended, so explicit installation is usually not required.

Installation​

import '@unchainedshop/plugins/worker/zombie-killer';

Purpose​

The Zombie Killer Worker removes "zombie" data - records that have become orphaned due to deletions or data inconsistencies:

  • Filter texts without parent filters
  • Assortment texts without parent assortments
  • Assortment media without parent assortments
  • Product texts without parent products
  • Product variations without parent products
  • Product media without parent products
  • Unreferenced files in product-media and assortment-media paths
  • Old bulk import streams older than a configurable age

Usage​

Trigger a cleanup:

mutation CleanupZombies {
addWork(
type: ZOMBIE_KILLER
input: {
bulkImportMaxAgeInDays: 5
}
) {
_id
status
}
}

Note: bulkImportMaxAgeInDays is optional and defaults to 5.

Input Parameters​

ParameterTypeDefaultDescription
bulkImportMaxAgeInDaysNumber5Days after which bulk import streams are deleted

Result​

The worker returns counts of deleted items:

{
"deletedFilterTextsCount": 0,
"deletedAssortmentTextsCount": 0,
"deletedAssortmentMediaCount": 0,
"deletedProductTextsCount": 0,
"deletedProductVariationsCount": 0,
"deletedProductMediaCount": 0,
"deletedFilesCount": 0
}

Consider running this worker periodically (e.g., weekly) to keep your database clean:

import { WorkerDirector, schedule } from '@unchainedshop/core';

WorkerDirector.configureAutoscheduling({
type: 'ZOMBIE_KILLER',
schedule: schedule.parse.cron('0 3 * * 0'), // Every Sunday at 3 AM
input: { bulkImportMaxAgeInDays: 7 },
});

Adapter Details​

PropertyValue
Keyshop.unchained.worker-plugin.zombie-killer
TypeZOMBIE_KILLER
Sourceworker/zombie-killer.ts