-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): delete expiration data regularly every day
- Loading branch information
Showing
9 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import { Module } from '@nestjs/common' | ||
import { ApiModule } from '~/api/api.module' | ||
import { TasksModule } from '~/tasks/tasks.module' | ||
import { SharedModule } from '~/shared.module' | ||
|
||
@Module({ imports: [ApiModule, SharedModule] }) | ||
@Module({ | ||
imports: [ | ||
ApiModule, | ||
TasksModule, | ||
SharedModule, | ||
], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Global, Module } from '@nestjs/common' | ||
import { ScheduleModule } from '@nestjs/schedule' | ||
import { BullModuleConfig } from '~/common' | ||
|
||
@Global() | ||
@Module({ imports: [BullModuleConfig] }) | ||
@Module({ imports: [BullModuleConfig, ScheduleModule.forRoot()] }) | ||
export class SharedModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Module } from '@nestjs/common' | ||
import { TasksService } from './tasks.service' | ||
import { PrismaService } from '~/common' | ||
|
||
@Module({ providers: [TasksService, PrismaService] }) | ||
export class TasksModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { Cron, CronExpression } from '@nestjs/schedule' | ||
import dayjs from 'dayjs' | ||
import { PrismaService } from '~/common' | ||
|
||
const interval = 30 | ||
|
||
@Injectable() | ||
export class TasksService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
@Cron(CronExpression.EVERY_DAY_AT_3AM) | ||
async handleDeleteExpiredData() { | ||
const options = { where: { createdAt: { lt: dayjs().subtract(interval, 'days').toDate() } } } | ||
await this.prisma.metric.deleteMany(options) | ||
await this.prisma.feedback.deleteMany(options) | ||
await this.prisma.pageView.deleteMany(options) | ||
await this.prisma.userView.deleteMany(options) | ||
await this.prisma.issue.deleteMany(options) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "EventUsersOnIssues" DROP CONSTRAINT "EventUsersOnIssues_eventUserId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "EventUsersOnIssues" DROP CONSTRAINT "EventUsersOnIssues_issueId_fkey"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "EventUsersOnIssues" ADD CONSTRAINT "EventUsersOnIssues_eventUserId_fkey" FOREIGN KEY ("eventUserId") REFERENCES "EventUser"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "EventUsersOnIssues" ADD CONSTRAINT "EventUsersOnIssues_issueId_fkey" FOREIGN KEY ("issueId") REFERENCES "Issue"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters