Skip to content

Commit 05ed615

Browse files
committed
feat: adds delete-expired
1 parent ca940d0 commit 05ed615

File tree

13 files changed

+85
-148
lines changed

13 files changed

+85
-148
lines changed

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ release: ## Bump version and create re
129129
clean: ## Cleanup temporary build artifacts
130130
@echo "${INFO} Cleaning working directory... 🧹"
131131
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/ .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache .unasyncd_cache/ .auto_pytabs_cache >/dev/null 2>&1
132-
@find . -name '*.egg-info' -exec rm -rf {} + >/dev/null 2>&1
133-
@find . -type f -name '*.egg' -exec rm -f {} + >/dev/null 2>&1
134-
@find . -name '*.pyc' -exec rm -f {} + >/dev/null 2>&1
135-
@find . -name '*.pyo' -exec rm -f {} + >/dev/null 2>&1
136-
@find . -name '*~' -exec rm -f {} + >/dev/null 2>&1
137-
@find . -name '__pycache__' -exec rm -rf {} + >/dev/null 2>&1
138-
@find . -name '.ipynb_checkpoints' -exec rm -rf {} + >/dev/null 2>&1
139-
@find . -name '*.so' -exec rm -f {} + >/dev/null 2>&1
140-
@find . -name '*.c' -exec rm -f {} + >/dev/null 2>&1
132+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*.egg-info' -exec rm -rf {} + >/dev/null 2>&1
133+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -type f -name '*.egg' -exec rm -f {} + >/dev/null 2>&1
134+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*.pyc' -exec rm -f {} + >/dev/null 2>&1
135+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*.pyo' -exec rm -f {} + >/dev/null 2>&1
136+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*~' -exec rm -f {} + >/dev/null 2>&1
137+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -type d -name '__pycache__' -exec rm -rf {} + >/dev/null 2>&1
138+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '.ipynb_checkpoints' -exec rm -rf {} + >/dev/null 2>&1
139+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*.so' -exec rm -f {} + >/dev/null 2>&1
140+
@find . \( -path ./.venv -o -path ./.git \) -prune -o -name '*.c' -exec rm -f {} + >/dev/null 2>&1
141141
@echo "${OK} Working directory cleaned"
142142
$(MAKE) docs-clean
143143

sqlspec/adapters/adbc/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class ADBCStore(BaseSQLSpecStore["AdbcConfig"]):
4949
Args:
5050
config: AdbcConfig instance.
5151
table_name: Name of the session table. Defaults to "sessions".
52-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
5352
5453
Example:
5554
from sqlspec.adapters.adbc import AdbcConfig
@@ -66,17 +65,14 @@ class ADBCStore(BaseSQLSpecStore["AdbcConfig"]):
6665

6766
__slots__ = ("_dialect",)
6867

69-
def __init__(
70-
self, config: "AdbcConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
71-
) -> None:
68+
def __init__(self, config: "AdbcConfig", table_name: str = "litestar_session") -> None:
7269
"""Initialize ADBC session store.
7370
7471
Args:
7572
config: AdbcConfig instance.
7673
table_name: Name of the session table.
77-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
7874
"""
79-
super().__init__(config, table_name, cleanup_probability)
75+
super().__init__(config, table_name)
8076
self._dialect: str | None = None
8177

8278
def _get_dialect(self) -> str:
@@ -374,9 +370,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
374370
"""
375371
await async_(self._set)(key, value, expires_in)
376372

377-
if self._should_cleanup():
378-
await self.delete_expired()
379-
380373
def _delete(self, key: str) -> None:
381374
"""Synchronous implementation of delete using ADBC driver."""
382375
p1 = self._get_param_placeholder(1)

sqlspec/adapters/aiosqlite/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class AiosqliteStore(BaseSQLSpecStore["AiosqliteConfig"]):
3030
Args:
3131
config: AiosqliteConfig instance.
3232
table_name: Name of the session table. Defaults to "sessions".
33-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
3433
3534
Example:
3635
from sqlspec.adapters.aiosqlite import AiosqliteConfig
@@ -43,17 +42,14 @@ class AiosqliteStore(BaseSQLSpecStore["AiosqliteConfig"]):
4342

4443
__slots__ = ()
4544

46-
def __init__(
47-
self, config: "AiosqliteConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
48-
) -> None:
45+
def __init__(self, config: "AiosqliteConfig", table_name: str = "litestar_session") -> None:
4946
"""Initialize AioSQLite session store.
5047
5148
Args:
5249
config: AiosqliteConfig instance.
5350
table_name: Name of the session table.
54-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
5551
"""
56-
super().__init__(config, table_name, cleanup_probability)
52+
super().__init__(config, table_name)
5753

5854
def _get_create_table_sql(self) -> str:
5955
"""Get SQLite CREATE TABLE SQL.
@@ -192,9 +188,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
192188
await conn.execute(sql, (key, data, expires_at_julian))
193189
await conn.commit()
194190

195-
if self._should_cleanup():
196-
await self.delete_expired()
197-
198191
async def delete(self, key: str) -> None:
199192
"""Delete a session by key.
200193

sqlspec/adapters/asyncmy/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class AsyncmyStore(BaseSQLSpecStore["AsyncmyConfig"]):
3030
Args:
3131
config: AsyncmyConfig instance.
3232
table_name: Name of the session table. Defaults to "sessions".
33-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
3433
3534
Example:
3635
from sqlspec.adapters.asyncmy import AsyncmyConfig
@@ -47,17 +46,14 @@ class AsyncmyStore(BaseSQLSpecStore["AsyncmyConfig"]):
4746

4847
__slots__ = ()
4948

50-
def __init__(
51-
self, config: "AsyncmyConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
52-
) -> None:
49+
def __init__(self, config: "AsyncmyConfig", table_name: str = "litestar_session") -> None:
5350
"""Initialize AsyncMy session store.
5451
5552
Args:
5653
config: AsyncmyConfig instance.
5754
table_name: Name of the session table.
58-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
5955
"""
60-
super().__init__(config, table_name, cleanup_probability)
56+
super().__init__(config, table_name)
6157

6258
def _get_create_table_sql(self) -> str:
6359
"""Get MySQL CREATE TABLE SQL with optimized schema.
@@ -184,9 +180,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
184180
await cursor.execute(sql, (key, data, naive_expires_at))
185181
await conn.commit()
186182

187-
if self._should_cleanup():
188-
await self.delete_expired()
189-
190183
async def delete(self, key: str) -> None:
191184
"""Delete a session by key.
192185

sqlspec/adapters/asyncpg/litestar/store.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class AsyncpgStore(BaseSQLSpecStore["AsyncpgConfig"]):
2626
2727
Args:
2828
config: AsyncpgConfig instance.
29-
table_name: Name of the session table. Defaults to "sessions".
30-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
29+
table_name: Name of the session table. Defaults to "litestar_session".
3130
3231
Example:
3332
from sqlspec.adapters.asyncpg import AsyncpgConfig
@@ -40,17 +39,14 @@ class AsyncpgStore(BaseSQLSpecStore["AsyncpgConfig"]):
4039

4140
__slots__ = ()
4241

43-
def __init__(
44-
self, config: "AsyncpgConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
45-
) -> None:
42+
def __init__(self, config: "AsyncpgConfig", table_name: str = "litestar_session") -> None:
4643
"""Initialize AsyncPG session store.
4744
4845
Args:
4946
config: AsyncpgConfig instance.
5047
table_name: Name of the session table.
51-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
5248
"""
53-
super().__init__(config, table_name, cleanup_probability)
49+
super().__init__(config, table_name)
5450

5551
def _get_create_table_sql(self) -> str:
5652
"""Get PostgreSQL CREATE TABLE SQL with optimized schema.
@@ -164,9 +160,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
164160
async with self._config.provide_connection() as conn:
165161
await conn.execute(sql, key, data, expires_at)
166162

167-
if self._should_cleanup():
168-
await self.delete_expired()
169-
170163
async def delete(self, key: str) -> None:
171164
"""Delete a session by key.
172165

sqlspec/adapters/bigquery/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class BigQueryStore(BaseSQLSpecStore["BigQueryConfig"]):
3939
Args:
4040
config: BigQueryConfig instance.
4141
table_name: Name of the session table. Defaults to "litestar_session".
42-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
4342
4443
Example:
4544
from sqlspec.adapters.bigquery import BigQueryConfig
@@ -52,17 +51,14 @@ class BigQueryStore(BaseSQLSpecStore["BigQueryConfig"]):
5251

5352
__slots__ = ()
5453

55-
def __init__(
56-
self, config: "BigQueryConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
57-
) -> None:
54+
def __init__(self, config: "BigQueryConfig", table_name: str = "litestar_session") -> None:
5855
"""Initialize BigQuery session store.
5956
6057
Args:
6158
config: BigQueryConfig instance.
6259
table_name: Name of the session table.
63-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
6460
"""
65-
super().__init__(config, table_name, cleanup_probability)
61+
super().__init__(config, table_name)
6662

6763
def _get_create_table_sql(self) -> str:
6864
"""Get BigQuery CREATE TABLE SQL with optimized schema.
@@ -220,9 +216,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
220216
"""
221217
await async_(self._set)(key, value, expires_in)
222218

223-
if self._should_cleanup():
224-
await self.delete_expired()
225-
226219
def _delete(self, key: str) -> None:
227220
"""Synchronous implementation of delete."""
228221
sql = f"DELETE FROM {self._table_name} WHERE session_id = @session_id"

sqlspec/adapters/duckdb/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class DuckdbStore(BaseSQLSpecStore["DuckDBConfig"]):
3737
Args:
3838
config: DuckDBConfig instance.
3939
table_name: Name of the session table. Defaults to "sessions".
40-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
4140
4241
Example:
4342
from sqlspec.adapters.duckdb import DuckDBConfig
@@ -50,17 +49,14 @@ class DuckdbStore(BaseSQLSpecStore["DuckDBConfig"]):
5049

5150
__slots__ = ()
5251

53-
def __init__(
54-
self, config: "DuckDBConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
55-
) -> None:
52+
def __init__(self, config: "DuckDBConfig", table_name: str = "litestar_session") -> None:
5653
"""Initialize DuckDB session store.
5754
5855
Args:
5956
config: DuckDBConfig instance.
6057
table_name: Name of the session table.
61-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
6258
"""
63-
super().__init__(config, table_name, cleanup_probability)
59+
super().__init__(config, table_name)
6460

6561
def _get_create_table_sql(self) -> str:
6662
"""Get DuckDB CREATE TABLE SQL.
@@ -222,9 +218,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
222218
"""
223219
await async_(self._set)(key, value, expires_in)
224220

225-
if self._should_cleanup():
226-
await self.delete_expired()
227-
228221
def _delete(self, key: str) -> None:
229222
"""Synchronous implementation of delete."""
230223
sql = f"DELETE FROM {self._table_name} WHERE session_id = ?"

sqlspec/adapters/oracledb/litestar/store.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class OracleAsyncStore(BaseSQLSpecStore["OracleAsyncConfig"]):
3131
Args:
3232
config: OracleAsyncConfig instance.
3333
table_name: Name of the session table. Defaults to "litestar_session".
34-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
3534
use_in_memory: Enable Oracle Database In-Memory Column Store for faster queries.
3635
Requires Oracle Database In-Memory license (paid feature). Defaults to False.
3736
@@ -57,21 +56,16 @@ class OracleAsyncStore(BaseSQLSpecStore["OracleAsyncConfig"]):
5756
__slots__ = ("_use_in_memory",)
5857

5958
def __init__(
60-
self,
61-
config: "OracleAsyncConfig",
62-
table_name: str = "litestar_session",
63-
cleanup_probability: float = 0.01,
64-
use_in_memory: bool = False,
59+
self, config: "OracleAsyncConfig", table_name: str = "litestar_session", use_in_memory: bool = False
6560
) -> None:
6661
"""Initialize Oracle session store.
6762
6863
Args:
6964
config: OracleAsyncConfig instance.
7065
table_name: Name of the session table.
71-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
7266
use_in_memory: Enable In-Memory Column Store (requires license).
7367
"""
74-
super().__init__(config, table_name, cleanup_probability)
68+
super().__init__(config, table_name)
7569
self._use_in_memory = use_in_memory
7670

7771
def _get_create_table_sql(self) -> str:
@@ -275,9 +269,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
275269
await cursor.execute(sql, {"session_id": key, "data": data, "expires_at": expires_at})
276270
await conn.commit()
277271

278-
if self._should_cleanup():
279-
await self.delete_expired()
280-
281272
async def delete(self, key: str) -> None:
282273
"""Delete a session by key.
283274
@@ -408,7 +399,6 @@ class OracleSyncStore(BaseSQLSpecStore["OracleSyncConfig"]):
408399
Args:
409400
config: OracleSyncConfig instance.
410401
table_name: Name of the session table. Defaults to "litestar_session".
411-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
412402
use_in_memory: Enable Oracle Database In-Memory Column Store for faster queries.
413403
Requires Oracle Database In-Memory license (paid feature). Defaults to False.
414404
@@ -430,21 +420,16 @@ class OracleSyncStore(BaseSQLSpecStore["OracleSyncConfig"]):
430420
__slots__ = ("_use_in_memory",)
431421

432422
def __init__(
433-
self,
434-
config: "OracleSyncConfig",
435-
table_name: str = "litestar_session",
436-
cleanup_probability: float = 0.01,
437-
use_in_memory: bool = False,
423+
self, config: "OracleSyncConfig", table_name: str = "litestar_session", use_in_memory: bool = False
438424
) -> None:
439425
"""Initialize Oracle sync session store.
440426
441427
Args:
442428
config: OracleSyncConfig instance.
443429
table_name: Name of the session table.
444-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
445430
use_in_memory: Enable In-Memory Column Store (requires license).
446431
"""
447-
super().__init__(config, table_name, cleanup_probability)
432+
super().__init__(config, table_name)
448433
self._use_in_memory = use_in_memory
449434

450435
def _get_create_table_sql(self) -> str:
@@ -657,9 +642,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
657642
"""
658643
await async_(self._set)(key, value, expires_in)
659644

660-
if self._should_cleanup():
661-
await self.delete_expired()
662-
663645
def _delete(self, key: str) -> None:
664646
"""Synchronous implementation of delete."""
665647
sql = f"DELETE FROM {self._table_name} WHERE session_id = :session_id"

sqlspec/adapters/psqlpy/litestar/store.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class PsqlpyStore(BaseSQLSpecStore["PsqlpyConfig"]):
2828
Args:
2929
config: PsqlpyConfig instance.
3030
table_name: Name of the session table. Defaults to "sessions".
31-
cleanup_probability: Probability of running cleanup on set (0.0-1.0).
3231
3332
Example:
3433
from sqlspec.adapters.psqlpy import PsqlpyConfig
@@ -41,17 +40,14 @@ class PsqlpyStore(BaseSQLSpecStore["PsqlpyConfig"]):
4140

4241
__slots__ = ()
4342

44-
def __init__(
45-
self, config: "PsqlpyConfig", table_name: str = "litestar_session", cleanup_probability: float = 0.01
46-
) -> None:
43+
def __init__(self, config: "PsqlpyConfig", table_name: str = "litestar_session") -> None:
4744
"""Initialize Psqlpy session store.
4845
4946
Args:
5047
config: PsqlpyConfig instance.
5148
table_name: Name of the session table.
52-
cleanup_probability: Probability of cleanup on set (0.0-1.0).
5349
"""
54-
super().__init__(config, table_name, cleanup_probability)
50+
super().__init__(config, table_name)
5551

5652
def _get_create_table_sql(self) -> str:
5753
"""Get PostgreSQL CREATE TABLE SQL with optimized schema.
@@ -168,9 +164,6 @@ async def set(self, key: str, value: "str | bytes", expires_in: "int | timedelta
168164
async with self._config.provide_connection() as conn:
169165
await conn.execute(sql, [key, data, expires_at])
170166

171-
if self._should_cleanup():
172-
await self.delete_expired()
173-
174167
async def delete(self, key: str) -> None:
175168
"""Delete a session by key.
176169

0 commit comments

Comments
 (0)