Skip to content

Commit

Permalink
New Model Mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
quodrum-glas committed Feb 13, 2024
1 parent 84a4c3e commit 0edff26
Show file tree
Hide file tree
Showing 14 changed files with 995 additions and 1,396 deletions.
40 changes: 40 additions & 0 deletions mopidy_tidal/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from functools import wraps
from cachetools import LRUCache, cached
from cachetools.keys import hashkey


_by_uri_cache = LRUCache(maxsize=16*1024)
_items_cache = LRUCache(maxsize=16*1024)
_futures_cache = LRUCache(maxsize=16*1024)

cached_by_uri = cached(
_by_uri_cache,
key=lambda *args, uri, **kwargs: hash(uri),
)
cached_items = cached(
_items_cache,
key=lambda item, *args, **kwargs: hashkey(item.uri, item.last_modified),
)
cached_future = cached(
_futures_cache,
key=lambda *args, uri, **kwargs: hash(uri),
)


def cache_by_uri(_callable):
@wraps(_callable)
def wrapper(*args, **kwargs):
item = _callable(*args, **kwargs)
_by_uri_cache[hash(item.ref.uri)] = item
return item
return wrapper


def cache_future(_callable):
@wraps(_callable)
def wrapper(*args, **kwargs):
item = _callable(*args, **kwargs)
if item:
_futures_cache[hash(item.ref.uri)] = item
return item
return wrapper
91 changes: 0 additions & 91 deletions mopidy_tidal/full_models_mappers.py

This file was deleted.

11 changes: 10 additions & 1 deletion mopidy_tidal/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ def to_timestamp(dt):
if not dt:
return 0
if isinstance(dt, str):
dt = datetime.datetime.fromisoformat(dt)
if dt.lower() == "today":
dt = datetime.datetime.combine(
datetime.datetime.now().date(),
datetime.time.min
).timestamp()
else:
dt = datetime.datetime.fromisoformat(dt)
if isinstance(dt, datetime.datetime):
dt = dt.timestamp()
return int(dt)

def return_none(*args, **kwargs):
return None
Loading

0 comments on commit 0edff26

Please sign in to comment.