Skip to content

Commit a91b015

Browse files
committed
Downgrade SQLite upserts to 'update if exists' + add 3.9-dev to travis vers
Unfortunately, SQLite upserts (`ON CONFLICT(name) DO UPDATE xxx`) are a rather new feature (released as of SQLite 3.24.0 2018-06-04), and it appears that the latest SQLite3 version in Ubuntu 18.04 (Bionic)'s repos is 3.22.0 - meaning that upserts are likely to be unusable on many systems. Due to this issue, upsert statements in `SqliteCacheManager` and `AsyncSqliteCacheManager` have been replaced with standard INSERT statements, and the `update_cache_key` method (in both sync and async classes) now uses a standard `UPDATE` statement, which should work on all systems. Additionally, `3.9-dev` has now been added to `.travis.yml`, but marked with `allow_failures` to avoid bugs in 3.9 (or problems with third-party libraries that haven't yet been patched to work with 3.9) causing the travis build to fail.
1 parent 3cb4ca1 commit a91b015

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ python:
88
- "3.6"
99
- "3.7"
1010
- "3.8"
11+
- "3.9-dev"
1112
- "nightly"
1213
jobs:
1314
allow_failures:
1415
# Sometimes nightly builds are broken, or contain breaking changes that affect dependencies we have
1516
# no control over. Thus we don't want a failed nightly run to cause Travis to consider the build broken.
1617
- python: 'nightly'
18+
- python: '3.9-dev'
1719
before_install:
18-
- sudo apt remove -y sqlite3
19-
- sudo apt-add-repository -y ppa:travis-ci/sqlite3
2020
- sudo apt-get update -qy
21-
- sudo apt-get -y install sqlite3
21+
- sudo apt-get install -qy sqlite3
2222
- sudo apt-get install -qy iputils-ping
2323
- "sudo rsync -avh 'rsync://files.privex.io/cdn/extras/GeoIP/*.mmdb' /usr/share/GeoIP/"
2424
install:

privex/helpers/cache/post_deps.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,22 @@ def cache_key_exists(self, name: str) -> bool:
125125

126126
def insert_cache_key(self, name: str, value: Any, expires_secs: Number = None, expires_at: Union[Number, datetime] = None):
127127
expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
128-
log.debug("Inserting/updating cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
128+
log.debug("Inserting cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
129+
# return self.action(
130+
# "INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?) "
131+
# "ON CONFLICT(name) DO UPDATE SET value=?,expires_at=?;",
132+
# (name, value, expires_at, value, expires_at)
133+
# )
129134
return self.action(
130-
"INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?) "
131-
"ON CONFLICT(name) DO "
132-
"UPDATE SET value=?,expires_at=?;",
133-
(name, value, expires_at, value, expires_at)
135+
"INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?);",
136+
(name, value, expires_at)
134137
)
135138

136139
def update_cache_key(self, name: str, value: Any, expires_secs: Number = None, expires_at: Union[Number, datetime] = None):
137-
# expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
140+
expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
138141
log.debug("Updating cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
139-
return self.insert_cache_key(name, value, expires_at=expires_at, expires_secs=expires_secs)
140-
# return self.action("UPDATE pvcache SET value = ?, expires_at = ? WHERE name = ?;", (value, name, expires_at))
142+
# return self.insert_cache_key(name, value, expires_at=expires_at, expires_secs=expires_secs)
143+
return self.action("UPDATE pvcache SET value = ?, expires_at = ? WHERE name = ?;", (value, expires_at, name))
141144

142145
def set_cache_key(self, name: str, value: Any, expires_secs: Number = None, expires_at: Union[Number, datetime] = None):
143146
# expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
@@ -225,19 +228,24 @@ async def cache_key_exists(self, name: str) -> bool:
225228

226229
async def insert_cache_key(self, name: str, value: Any, expires_secs: Number = None, expires_at: Union[Number, datetime] = None):
227230
expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
228-
log.debug("Inserting/updating cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
231+
log.debug("Inserting cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
232+
# return await await_if_needed(self.action(
233+
# "INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?) "
234+
# "ON CONFLICT(name) DO UPDATE SET value=?,expires_at=?;",
235+
# (name, value, expires_at, value, expires_at)
236+
# ))
229237
return await await_if_needed(self.action(
230-
"INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?) "
231-
"ON CONFLICT(name) DO "
232-
"UPDATE SET value=?,expires_at=?;",
233-
(name, value, expires_at, value, expires_at)
238+
"INSERT INTO pvcache (name, value, expires_at) VALUES (?, ?, ?);",
239+
(name, value, expires_at)
234240
))
235241

236242
async def update_cache_key(self, name: str, value: Any, expires_secs: Number = None, expires_at: Union[Number, datetime] = None):
237-
# expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
243+
expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)
238244
log.debug("Updating cache key '%s' with expires_at = '%s' and value: %s", name, expires_at, value)
239-
return await self.insert_cache_key(name, value, expires_at=expires_at, expires_secs=expires_secs)
240-
# return self.action("UPDATE pvcache SET value = ?, expires_at = ? WHERE name = ?;", (value, name, expires_at))
245+
# return await self.insert_cache_key(name, value, expires_at=expires_at, expires_secs=expires_secs)
246+
return await await_if_needed(
247+
self.action("UPDATE pvcache SET value = ?, expires_at = ? WHERE name = ?;", (value, expires_at, name))
248+
)
241249

242250
async def set_cache_key(self, name: str, value: T, expires_secs: Number = None, expires_at: Union[Number, datetime] = None) -> T:
243251
expires_at = self._calc_expires(expires_at=expires_at, expires_secs=expires_secs)

0 commit comments

Comments
 (0)