Skip to content

Open-source status page, incident response and uptime monitoring

remove dead code (#1711)

Thibault Le Ouayeeb27e10095e
diff --git a/apps/server/src/libs/cache/index.ts b/apps/server/src/libs/cache/index.ts
deleted file mode 100644
index 33dac29e2..000000000
--- a/apps/server/src/libs/cache/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./memory";
diff --git a/apps/server/src/libs/cache/memory.ts b/apps/server/src/libs/cache/memory.ts
deleted file mode 100644
index c9b7e33cc..000000000
--- a/apps/server/src/libs/cache/memory.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-// Props to https://github.com/isaacs/node-lru-cache?tab=readme-ov-file#storage-bounds-safety
-
-export class MemoryCache {
- private ttl: number;
- private data: Map<string, unknown>;
- private timers: Map<string, NodeJS.Timeout>;
-
- constructor(defaultTTL = 60 * 1000) {
- this.ttl = defaultTTL;
- this.data = new Map();
- this.timers = new Map();
- }
-
- set<T>(key: string, value: T, ttl = this.ttl) {
- if (this.timers.has(key)) {
- clearTimeout(this.timers.get(key));
- }
- this.timers.set(
- key,
- setTimeout(() => this.delete(key), ttl),
- );
- this.data.set(key, value);
- return value;
- }
-
- get<T>(key: string) {
- return this.data.get(key) as T;
- }
-
- has(key: string) {
- return this.data.has(key);
- }
-
- delete(key: string) {
- if (this.timers.has(key)) {
- clearTimeout(this.timers.get(key));
- }
- this.timers.delete(key);
- return this.data.delete(key);
- }
-
- clear() {
- this.data.clear();
- for (const timer of Array.from(this.timers.values())) {
- clearTimeout(timer);
- }
- this.timers.clear();
- }
-}
-
-const _cache = new MemoryCache();
diff --git a/packages/api/src/router/maintenance.ts b/packages/api/src/router/maintenance.ts
index 58a85bef8..c7e7ad391 100644
--- a/packages/api/src/router/maintenance.ts
+++ b/packages/api/src/router/maintenance.ts
@@ -11,7 +11,6 @@ import {
lte,
} from "@openstatus/db";
import {
- insertMaintenanceSchema,
maintenance,
maintenancesToMonitors,
monitor,
@@ -23,31 +22,6 @@ import { TRPCError } from "@trpc/server";
import { createTRPCRouter, protectedProcedure } from "../trpc";
export const maintenanceRouter = createTRPCRouter({
- create: protectedProcedure
- .meta({ track: Events.CreateMaintenance })
- .input(insertMaintenanceSchema)
- .mutation(async (opts) => {
- const _maintenance = await opts.ctx.db
- .insert(maintenance)
- .values({ ...opts.input, workspaceId: opts.ctx.workspace.id })
- .returning()
- .get();
-
- if (opts.input.monitors?.length) {
- await opts.ctx.db
- .insert(maintenancesToMonitors)
- .values(
- opts.input.monitors.map((monitorId) => ({
- maintenanceId: _maintenance.id,
- monitorId,
- })),
- )
- .returning()
- .get();
- }
-
- return _maintenance;
- }),
getById: protectedProcedure
.input(z.object({ id: z.number() }))
.query(async (opts) => {
@@ -122,75 +96,7 @@ export const maintenanceRouter = createTRPCRouter({
.all();
return _maintenances;
}),
- updateLegacy: protectedProcedure
- .meta({ track: Events.UpdateMaintenance })
- .input(insertMaintenanceSchema)
- .mutation(async (opts) => {
- if (!opts.input.id) {
- throw new TRPCError({ code: "BAD_REQUEST", message: "id is required" });
- }
- const _maintenance = await opts.ctx.db
- .update(maintenance)
- .set({
- ...opts.input,
- workspaceId: opts.ctx.workspace.id,
- updatedAt: new Date(),
- })
- .where(
- and(
- eq(maintenance.id, opts.input.id),
- eq(maintenance.workspaceId, opts.ctx.workspace.id),
- ),
- )
- .returning()
- .get();
-
- const _maintenancesToMonitors = await opts.ctx.db
- .select()
- .from(maintenancesToMonitors)
- .where(eq(maintenancesToMonitors.maintenanceId, _maintenance.id))
- .all();
-
- const _monitorsIds = _maintenancesToMonitors.map(
- ({ monitorId }) => monitorId,
- );
-
- const added = opts.input.monitors?.filter(
- (monitor) => !_monitorsIds.includes(monitor),
- );
-
- if (added?.length) {
- await opts.ctx.db
- .insert(maintenancesToMonitors)
- .values(
- added.map((monitorId) => ({
- maintenanceId: _maintenance.id,
- monitorId,
- })),
- )
- .returning()
- .get();
- }
-
- const removed = _monitorsIds.filter(
- (monitor) => !opts.input.monitors?.includes(monitor),
- );
-
- if (removed?.length) {
- await opts.ctx.db
- .delete(maintenancesToMonitors)
- .where(
- and(
- eq(maintenancesToMonitors.maintenanceId, _maintenance.id),
- inArray(maintenancesToMonitors.monitorId, removed),
- ),
- )
- .run();
- }
-
- return _maintenance;
- }),
delete: protectedProcedure
.meta({ track: Events.DeleteMaintenance })
.input(z.object({ id: z.number() }))