Use a deterministic hash

This commit is contained in:
Sumner Evans
2020-04-23 10:44:55 -06:00
parent a36aac26e9
commit d28c389bb2
5 changed files with 87 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ from typing import Any, Optional, Sequence
from peewee import (
BooleanField,
CompositeKey,
DoubleField,
ensure_tuple,
ForeignKeyField,
@@ -23,14 +24,6 @@ database = SqliteDatabase(None)
# Custom Fields
# =============================================================================
class DurationField(DoubleField):
def db_value(self, value: timedelta) -> Optional[float]:
return value.total_seconds() if value else None
def python_value(self, value: Optional[float]) -> Optional[timedelta]:
return timedelta(seconds=value) if value else None
class CacheConstantsField(TextField):
def db_value(self, value: CachingAdapter.FunctionNames) -> str:
return value.value
@@ -39,6 +32,14 @@ class CacheConstantsField(TextField):
return CachingAdapter.FunctionNames(value)
class DurationField(DoubleField):
def db_value(self, value: timedelta) -> Optional[float]:
return value.total_seconds() if value else None
def python_value(self, value: Optional[float]) -> Optional[timedelta]:
return timedelta(seconds=value) if value else None
class TzDateTimeField(TextField):
def db_value(self, value: Optional[datetime]) -> Optional[str]:
return value.isoformat() if value else None
@@ -204,10 +205,13 @@ class Song(BaseModel):
class CacheInfo(BaseModel):
query_name = CacheConstantsField(unique=True, primary_key=True)
params_hash = IntegerField(null=False)
query_name = CacheConstantsField()
params_hash = TextField()
last_ingestion_time = TzDateTimeField(null=False)
class Meta:
primary_key = CompositeKey('query_name', 'params_hash')
class Playlist(BaseModel):
id = TextField(unique=True, primary_key=True)