Delete old data automatically #3230
Replies: 5 comments 1 reply
-
|
This should be implemented as a cron job and is outside the scope of the app. The app has no concept of jobs. |
Beta Was this translation helpful? Give feedback.
-
How about add a background worker and expose a config, letting user choose how long the data should be stored? |
Beta Was this translation helpful? Give feedback.
-
|
Another idea would be to create a possibility to delete old data manually and expose that via a umami-cli or a local endpoint so admins can easily create a cronjob for that. |
Beta Was this translation helpful? Give feedback.
-
|
Also, please reopen this issue to discuss. |
Beta Was this translation helpful? Give feedback.
-
|
Wouldn't it be similar to the reset function with the only difference that there would be a second where filter? umami/src/queries/prisma/website.ts Lines 158 to 190 in 1552a3f Something like: export async function resetWebsiteOlderTwoMonths(
websiteId: string,
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
const { client, transaction } = prisma;
const cloudMode = !!process.env.cloudMode;
const now = new Date();
const twoMonthsAgo = new Date(now);
twoMonthsAgo.setMonth(now.getMonth() - 2);
return transaction([
client.eventData.deleteMany({
where: {
id: websiteId,
lte: twoMonthsAgo
},
}),
client.sessionData.deleteMany({
where: {
id: websiteId,
lte: twoMonthsAgo
},
}),
client.websiteEvent.deleteMany({
where: {
id: websiteId,
lte: twoMonthsAgo
},
}),
client.session.deleteMany({
where: {
id: websiteId,
lte: twoMonthsAgo
},
}),
client.website.update({
where: { id: websiteId },
data: {
resetAt: now,
},
}),
]).then(async data => {
if (cloudMode) {
await redis.client.set(`website:${websiteId}`, data[3]);
}
return data;
});
}If your open to such a option in the settings + cli endpoint I'd be happy to contribute a PR. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Originally posted by @ncovercash in #292
As this request got buried in another issue that was already merged I'd like to come back to this and open a separate issue for this.
I too am only interested in data from the last 2 month.
I'd appreciate a possibility to automatically truncate all data that's older than a specified time range. This could be a simple cronjob that deletes old data once a day.
Beta Was this translation helpful? Give feedback.
All reactions