event_queue slimmed e indexes
This commit is contained in:
parent
14343ed611
commit
723bc9fc31
4 changed files with 16 additions and 6 deletions
13
apps/db/migrations/52_indexes.up.sql
Normal file
13
apps/db/migrations/52_indexes.up.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
ALTER TABLE IF EXISTS public.event_queue DROP COLUMN IF EXISTS status;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS event_queue_lock_idx
|
||||
ON public.event_queue (lock_expires);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS event_queue_event_id_uq
|
||||
ON public.event_queue (event_id);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS user_invites_token_idx
|
||||
ON public.user_invites (token);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS emails_user_id_idx
|
||||
ON public.emails (user_id);
|
||||
|
|
@ -11,8 +11,6 @@ export default interface EventQueueTable {
|
|||
lock_expires: ColumnType<Date, Date | string, Date | string>;
|
||||
|
||||
data: ColumnType<unknown | null, unknown | null, unknown | null>;
|
||||
|
||||
status: ColumnType<string, string | undefined, string>;
|
||||
}
|
||||
|
||||
export type EventQueue = Selectable<EventQueueTable>;
|
||||
|
|
@ -27,19 +25,16 @@ export const EventQueueSchema = z.object({
|
|||
event_id: eventQueueEventId,
|
||||
lock_expires: z.date(),
|
||||
data: z.unknown().nullable(),
|
||||
status: z.string(),
|
||||
});
|
||||
|
||||
export const NewEventQueueSchema = z.object({
|
||||
event_id: eventQueueEventId.optional(),
|
||||
lock_expires: z.union([z.date(), z.string()]).pipe(z.coerce.date()),
|
||||
data: z.unknown().optional().nullable(),
|
||||
status: z.string().optional(),
|
||||
});
|
||||
|
||||
export const EventQueueUpdateSchema = z.object({
|
||||
event_id: eventQueueEventId.optional(),
|
||||
lock_expires: z.union([z.date(), z.string()]).pipe(z.coerce.date()).optional(),
|
||||
data: z.unknown().optional().nullable(),
|
||||
status: z.string().optional(),
|
||||
});
|
||||
|
|
@ -5,6 +5,7 @@ import type { default as UsersTable } from './Users';
|
|||
import type { default as ChatsEtichetteTable } from './ChatsEtichette';
|
||||
import type { default as TestiEStringheTable } from './TestiEStringhe';
|
||||
import type { default as UserEtichetteTable } from './UserEtichette';
|
||||
import type { default as TypingStatusTable } from './TypingStatus';
|
||||
import type { default as AppuntiTable } from './Appunti';
|
||||
import type { default as UsersStorageTable } from './UsersStorage';
|
||||
import type { default as ServizioAnnunciTable } from './ServizioAnnunci';
|
||||
|
|
@ -45,6 +46,8 @@ export default interface PublicSchema {
|
|||
|
||||
user_etichette: UserEtichetteTable;
|
||||
|
||||
typing_status: TypingStatusTable;
|
||||
|
||||
appunti: AppuntiTable;
|
||||
|
||||
users_storage: UsersStorageTable;
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ const getEventsFromQueue = async () => {
|
|||
const events = await db
|
||||
.selectFrom("event_queue")
|
||||
.selectAll()
|
||||
.where("status", "=", "pending")
|
||||
.where("event_queue.lock_expires", "<=", new Date())
|
||||
.execute();
|
||||
return events;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue