mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-09 18:08:00 +00:00
cache fixes
* make sure Item.updated is a datetime object * remove id column when creating Item objects in SqlCache
This commit is contained in:
parent
2d641ea183
commit
4c4dd3566b
|
@ -69,6 +69,7 @@ class Item:
|
|||
def from_data(cls: type[Item], *args) -> Item:
|
||||
data = cls(*args)
|
||||
data.value = deserialize_value(data.value, data.value_type)
|
||||
data.updated = datetime.fromtimestamp(data.updated, tz = timezone.utc)
|
||||
return data
|
||||
|
||||
|
||||
|
@ -153,6 +154,7 @@ class SqlCache(Cache):
|
|||
if not (row := cur.one()):
|
||||
raise KeyError(f'{namespace}:{key}')
|
||||
|
||||
row.pop('id', None)
|
||||
return Item.from_data(*tuple(row.values()))
|
||||
|
||||
|
||||
|
@ -178,7 +180,9 @@ class SqlCache(Cache):
|
|||
}
|
||||
|
||||
with self._db.connection() as conn:
|
||||
for row in conn.exec_statement('set-cache-item', params):
|
||||
with conn.exec_statement('set-cache-item', params) as conn:
|
||||
row = conn.one()
|
||||
row.pop('id', None)
|
||||
return Item.from_data(*tuple(row.values()))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue