A hook extension that automatically removes old activity records from the d9 database, helping keep your instance performant and free of unnecessary historical data.
- Automatically deletes activity entries older than a configurable threshold.
- Lightweight background hook – minimal performance impact.
- Easy to install and update.
Clone the repository and build the extension:
git clone https://github.com/william-perez-dev/d9-activity-cleanup.gitcd d9-activity-cleanupnpm installnpm run build- Create the required folder inside your d9 instance (if it doesn't already exist):
extensions/hooks/d9-activity-cleanup- Copy the built file
dist/index.cjsfrom this repository into that folder.
mkdir -p /path/to/your/d9-instance/extensions/hooks/d9-activity-cleanupcp dist/index.cjs /path/to/your/d9-instance/extensions/hooks/d9-activity-cleanup/To enable and customize the activity cleanup behavior, add the following variables to your d9 instance .env file:
ACTIVITY_CLEANUP_ALLOWED=true # false by default – enables the cleanup hook
ACTIVITY_CLEANUP_SCHEDULE='* 3 * * *' # '0 0 * * *' by default (daily at midnight)
ACTIVITY_CLEANUP_RETENTION_DAYS=90 # 30 days by default – delete activities older than this
ACTIVITY_CLEANUP_BATCH_SIZE=1000 # 1000 by default – number of records deleted per batch