Skip to content

Commit 8aaed6d

Browse files
Revert cache change
1 parent 85518fb commit 8aaed6d

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

.github/workflows/testing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup Python
3939
run: uv python install ${{ matrix.python-version }}
4040
- name: Install project
41-
run: uv sync --dev
41+
run: uv sync --group tests
4242
- name: Run tests
4343
env:
4444
COMICVINE__API_KEY: IGNORED

simyan/comicvine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _get_request(
178178
cache_key = re.sub(r"(.+api_key=)(.+?)(&.+)", r"\1*****\3", cache_key)
179179

180180
if self.cache and not skip_cache:
181-
cached_response = self.cache.select(url=cache_key)
181+
cached_response = self.cache.select(query=cache_key)
182182
if cached_response:
183183
return cached_response
184184

@@ -187,7 +187,7 @@ def _get_request(
187187
raise ServiceError(response["error"])
188188

189189
if self.cache and not skip_cache:
190-
self.cache.insert(url=cache_key, response=response)
190+
self.cache.insert(query=cache_key, response=response)
191191

192192
return response
193193

simyan/schemas/issue.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@ class Issue(BasicIssue):
103103
mode="before",
104104
)
105105
def handle_blank_list(cls, value: Union[str, list, None]) -> list:
106+
"""Convert a blank or None value to an empty list.
107+
108+
Args:
109+
value: The value to check.
110+
111+
Returns:
112+
An empty list if the value is None or an empty string, otherwise the original list.
113+
"""
106114
return value or []

simyan/sqlite_cache.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,54 @@ def __init__(self, path: Optional[Path] = None, expiry: Optional[int] = 14):
2727
self.connection = sqlite3.connect(path or get_cache_root() / "cache.sqlite")
2828
self.connection.row_factory = sqlite3.Row
2929

30-
self.connection.execute("CREATE TABLE IF NOT EXISTS queries (url, response, query_date);")
30+
self.connection.execute("CREATE TABLE IF NOT EXISTS queries (query, response, query_date);")
3131
self.cleanup()
3232

33-
def select(self, url: str) -> dict[str, Any]:
33+
def select(self, query: str) -> dict[str, Any]:
3434
"""Retrieve data from the cache database.
3535
3636
Args:
37-
url: Url string used as key.
37+
query: Url string used as key.
3838
3939
Returns:
4040
Empty dict or select results.
4141
"""
4242
if self.expiry:
4343
expiry = datetime.now(tz=timezone.utc).astimezone().date() - timedelta(days=self.expiry)
4444
cursor = self.connection.execute(
45-
"SELECT * FROM queries WHERE url = ? and query_date > ?;", (url, expiry.isoformat())
45+
"SELECT * FROM queries WHERE query = ? and query_date > ?;",
46+
(query, expiry.isoformat()),
4647
)
4748
else:
48-
cursor = self.connection.execute("SELECT * FROM queries WHERE url = ?;", (url,))
49+
cursor = self.connection.execute("SELECT * FROM queries WHERE query = ?;", (query,))
4950
if results := cursor.fetchone():
5051
return json.loads(results["response"])
5152
return {}
5253

53-
def insert(self, url: str, response: dict[str, Any]) -> None:
54+
def insert(self, query: str, response: dict[str, Any]) -> None:
5455
"""Insert data into the cache database.
5556
5657
Args:
57-
url: Url string used as key.
58+
query: Url string used as key.
5859
response: Response dict from url.
5960
"""
6061
self.connection.execute(
61-
"INSERT INTO queries (url, response, query_date) VALUES (?, ?, ?);",
62+
"INSERT INTO queries (query, response, query_date) VALUES (?, ?, ?);",
6263
(
63-
url,
64+
query,
6465
json.dumps(response),
6566
datetime.now(tz=timezone.utc).astimezone().date().isoformat(),
6667
),
6768
)
6869
self.connection.commit()
6970

70-
def delete(self, url: str) -> None:
71+
def delete(self, query: str) -> None:
7172
"""Remove entry from the cache with the provided url.
7273
7374
Args:
74-
url: Url string used as key.
75+
query: Url string used as key.
7576
"""
76-
self.connection.execute("DELETE FROM queries WHERE url = ?;", (url,))
77+
self.connection.execute("DELETE FROM queries WHERE query = ?;", (query,))
7778
self.connection.commit()
7879

7980
def cleanup(self) -> None:

tests/cache.sqlite

-4 KB
Binary file not shown.

0 commit comments

Comments
 (0)