Skip to content

Commit 38a800d

Browse files
committed
Create index for periodic session deletion
1 parent 9b01b8b commit 38a800d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Network/Wai/Session/PostgreSQL.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ instance WithPostgreSQLConn (Pool Connection) where
118118
qryCreateTable1 :: Query
119119
qryCreateTable1 = "CREATE TABLE wai_pg_sessions (id bigserial NOT NULL, session_key character varying NOT NULL, session_created_at bigint NOT NULL, session_last_access bigint NOT NULL, session_invalidate_key boolean NOT NULL DEFAULT false, CONSTRAINT wai_pg_sessions_pkey PRIMARY KEY (id), CONSTRAINT wai_pg_sessions_session_key UNIQUE (session_key)) WITH ( OIDS=FALSE );"
120120

121+
qryCreateIndex1 :: Query
122+
qryCreateIndex1 = "CREATE INDEX idx_session_last_access ON public.wai_pg_sessions USING btree (session_last_access);"
123+
121124
qryCreateTable2 :: Query
122125
qryCreateTable2 = "CREATE TABLE wai_pg_session_data ( id bigserial NOT NULL, wai_pg_session bigint, key bytea, value bytea, CONSTRAINT wai_pg_session_data_pkey PRIMARY KEY (id), CONSTRAINT wai_pg_session_data_wai_pg_session_fkey FOREIGN KEY (wai_pg_session) REFERENCES wai_pg_sessions (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE CASCADE, CONSTRAINT wai_pg_session_data_wai_pg_session_key_key UNIQUE (wai_pg_session, key) ) WITH (OIDS=FALSE);"
123126

@@ -168,6 +171,7 @@ dbStore pool stos = do
168171
unerror $ do
169172
void $ execute_ conn qryCreateTable1
170173
void $ execute_ conn qryCreateTable2
174+
void $ execute_ conn qryCreateIndex1
171175
storeSettingsLog stos "Created tables."
172176
return $ dbStore' pool stos
173177

0 commit comments

Comments
 (0)