Openstatus www.openstatus.dev

remove dead code (#1711)

* remove dead code

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
eeb27e10 c46f64d4

-146
-1
apps/server/src/libs/cache/index.ts
··· 1 - export * from "./memory";
-51
apps/server/src/libs/cache/memory.ts
··· 1 - // Props to https://github.com/isaacs/node-lru-cache?tab=readme-ov-file#storage-bounds-safety 2 - 3 - export class MemoryCache { 4 - private ttl: number; 5 - private data: Map<string, unknown>; 6 - private timers: Map<string, NodeJS.Timeout>; 7 - 8 - constructor(defaultTTL = 60 * 1000) { 9 - this.ttl = defaultTTL; 10 - this.data = new Map(); 11 - this.timers = new Map(); 12 - } 13 - 14 - set<T>(key: string, value: T, ttl = this.ttl) { 15 - if (this.timers.has(key)) { 16 - clearTimeout(this.timers.get(key)); 17 - } 18 - this.timers.set( 19 - key, 20 - setTimeout(() => this.delete(key), ttl), 21 - ); 22 - this.data.set(key, value); 23 - return value; 24 - } 25 - 26 - get<T>(key: string) { 27 - return this.data.get(key) as T; 28 - } 29 - 30 - has(key: string) { 31 - return this.data.has(key); 32 - } 33 - 34 - delete(key: string) { 35 - if (this.timers.has(key)) { 36 - clearTimeout(this.timers.get(key)); 37 - } 38 - this.timers.delete(key); 39 - return this.data.delete(key); 40 - } 41 - 42 - clear() { 43 - this.data.clear(); 44 - for (const timer of Array.from(this.timers.values())) { 45 - clearTimeout(timer); 46 - } 47 - this.timers.clear(); 48 - } 49 - } 50 - 51 - const _cache = new MemoryCache();
-94
packages/api/src/router/maintenance.ts
··· 11 11 lte, 12 12 } from "@openstatus/db"; 13 13 import { 14 - insertMaintenanceSchema, 15 14 maintenance, 16 15 maintenancesToMonitors, 17 16 monitor, ··· 23 22 import { createTRPCRouter, protectedProcedure } from "../trpc"; 24 23 25 24 export const maintenanceRouter = createTRPCRouter({ 26 - create: protectedProcedure 27 - .meta({ track: Events.CreateMaintenance }) 28 - .input(insertMaintenanceSchema) 29 - .mutation(async (opts) => { 30 - const _maintenance = await opts.ctx.db 31 - .insert(maintenance) 32 - .values({ ...opts.input, workspaceId: opts.ctx.workspace.id }) 33 - .returning() 34 - .get(); 35 - 36 - if (opts.input.monitors?.length) { 37 - await opts.ctx.db 38 - .insert(maintenancesToMonitors) 39 - .values( 40 - opts.input.monitors.map((monitorId) => ({ 41 - maintenanceId: _maintenance.id, 42 - monitorId, 43 - })), 44 - ) 45 - .returning() 46 - .get(); 47 - } 48 - 49 - return _maintenance; 50 - }), 51 25 getById: protectedProcedure 52 26 .input(z.object({ id: z.number() })) 53 27 .query(async (opts) => { ··· 122 96 .all(); 123 97 return _maintenances; 124 98 }), 125 - updateLegacy: protectedProcedure 126 - .meta({ track: Events.UpdateMaintenance }) 127 - .input(insertMaintenanceSchema) 128 - .mutation(async (opts) => { 129 - if (!opts.input.id) { 130 - throw new TRPCError({ code: "BAD_REQUEST", message: "id is required" }); 131 - } 132 99 133 - const _maintenance = await opts.ctx.db 134 - .update(maintenance) 135 - .set({ 136 - ...opts.input, 137 - workspaceId: opts.ctx.workspace.id, 138 - updatedAt: new Date(), 139 - }) 140 - .where( 141 - and( 142 - eq(maintenance.id, opts.input.id), 143 - eq(maintenance.workspaceId, opts.ctx.workspace.id), 144 - ), 145 - ) 146 - .returning() 147 - .get(); 148 - 149 - const _maintenancesToMonitors = await opts.ctx.db 150 - .select() 151 - .from(maintenancesToMonitors) 152 - .where(eq(maintenancesToMonitors.maintenanceId, _maintenance.id)) 153 - .all(); 154 - 155 - const _monitorsIds = _maintenancesToMonitors.map( 156 - ({ monitorId }) => monitorId, 157 - ); 158 - 159 - const added = opts.input.monitors?.filter( 160 - (monitor) => !_monitorsIds.includes(monitor), 161 - ); 162 - 163 - if (added?.length) { 164 - await opts.ctx.db 165 - .insert(maintenancesToMonitors) 166 - .values( 167 - added.map((monitorId) => ({ 168 - maintenanceId: _maintenance.id, 169 - monitorId, 170 - })), 171 - ) 172 - .returning() 173 - .get(); 174 - } 175 - 176 - const removed = _monitorsIds.filter( 177 - (monitor) => !opts.input.monitors?.includes(monitor), 178 - ); 179 - 180 - if (removed?.length) { 181 - await opts.ctx.db 182 - .delete(maintenancesToMonitors) 183 - .where( 184 - and( 185 - eq(maintenancesToMonitors.maintenanceId, _maintenance.id), 186 - inArray(maintenancesToMonitors.monitorId, removed), 187 - ), 188 - ) 189 - .run(); 190 - } 191 - 192 - return _maintenance; 193 - }), 194 100 delete: protectedProcedure 195 101 .meta({ track: Events.DeleteMaintenance }) 196 102 .input(z.object({ id: z.number() }))