feat: noteの取得をcacheするように #14

pull/20/head
yupix 2 years ago
parent ab97fdbdb1
commit 34ae2a33ba
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -2,6 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from mipac.exception import ParameterError
from mipac.http import HTTPClient, Route
from mipac.manager.favorite import FavoriteManager
@ -13,7 +14,13 @@ from mipac.types.note import INote
__all__ = ['NoteActions']
from mipac.util import check_multi_arg, remove_dict_empty
from mipac.util import (
check_multi_arg,
remove_dict_empty,
key_builder,
get_cache_key,
cache,
)
if TYPE_CHECKING:
from mipac.client import ClientActions
@ -269,7 +276,8 @@ class NoteActions:
poll=poll,
) # TODO: filesを受け取るように
async def get_note(self, note_id: Optional[str] = None) -> Note:
@cache(group='get_note')
async def get(self, note_id: Optional[str] = None, **kwargs) -> Note:
"""
ノートを取得します
@ -292,6 +300,17 @@ class NoteActions:
)
return Note(res, client=self.__client)
@cache(group='get_note', override=True)
async def fetch(self, note_id: Optional[str] = None) -> Note:
note_id = note_id or self.__note_id
res = await self.__session.request(
Route('POST', '/api/notes/show'),
json={'noteId': note_id},
auth=True,
lower=True,
)
return Note(res, client=self.__client)
async def get_replies(
self,
since_id: Optional[str] = None,

Loading…
Cancel
Save