Skip to content

Commit

Permalink
Remove unused now argument to Storage.get_entries() and Search.search…
Browse files Browse the repository at this point in the history
…_entries().

For #325.
  • Loading branch information
lemon24 committed Oct 28, 2023
1 parent cd261f0 commit abf1c1b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 71 deletions.
7 changes: 2 additions & 5 deletions src/reader/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ def _insert_into_search_one_chunk(self) -> bool:
def search_entries(
self,
query: str,
now: datetime,
filter_options: EntryFilterOptions = EntryFilterOptions(), # noqa: B008
sort: SearchSortOrder = 'relevant',
limit: int | None = None,
Expand All @@ -758,12 +757,12 @@ def search_entries(
last = None
if starting_after:
if sort == 'recent':
last = self.storage.get_entry_last(now, sort, starting_after)
last = self.storage.get_entry_last(sort, starting_after)
else:
last = self.search_entry_last(query, starting_after)

rv = join_paginated_iter(
partial(self.search_entries_page, query, now, filter_options, sort), # type: ignore[arg-type]
partial(self.search_entries_page, query, filter_options, sort), # type: ignore[arg-type]
self.chunk_size,
last,
limit or 0,
Expand All @@ -773,7 +772,6 @@ def search_entries(
assert not starting_after
it = self.search_entries_page(
query,
now,
filter_options,
sort,
min(limit, self.chunk_size or limit) if limit else self.chunk_size,
Expand Down Expand Up @@ -810,7 +808,6 @@ def search_entry_last(self, query: str, entry: tuple[str, str]) -> tuple[Any, ..
def search_entries_page(
self,
query: str,
now: datetime,
filter_options: EntryFilterOptions = EntryFilterOptions(), # noqa: B008
sort: SearchSortOrder = 'relevant',
chunk_size: int | None = None,
Expand Down
13 changes: 3 additions & 10 deletions src/reader/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,6 @@ def delete_entries(

def get_entries(
self,
now: datetime,
filter_options: EntryFilterOptions = EntryFilterOptions(), # noqa: B008
sort: EntrySortOrder = 'recent',
limit: int | None = None,
Expand All @@ -1065,17 +1064,14 @@ def get_entries(
# TODO: deduplicate
if sort == 'recent':
rv = join_paginated_iter(
partial(self.get_entries_page, now, filter_options, sort), # type: ignore[arg-type]
partial(self.get_entries_page, filter_options, sort), # type: ignore[arg-type]
self.chunk_size,
self.get_entry_last(now, sort, starting_after)
if starting_after
else None,
self.get_entry_last(sort, starting_after) if starting_after else None,
limit or 0,
)
elif sort == 'random':
assert not starting_after
it = self.get_entries_page(
now,
filter_options,
sort,
min(limit, self.chunk_size or limit) if limit else self.chunk_size,
Expand All @@ -1087,9 +1083,7 @@ def get_entries(
yield from rv

@wrap_exceptions(StorageError)
def get_entry_last(
self, now: datetime, sort: str, entry: tuple[str, str]
) -> tuple[Any, ...]:
def get_entry_last(self, sort: str, entry: tuple[str, str]) -> tuple[Any, ...]:
# TODO: make this method private?

feed_url, entry_id = entry
Expand All @@ -1114,7 +1108,6 @@ def get_entry_last(
@wrap_exceptions_iter(StorageError)
def get_entries_page(
self,
now: datetime,
filter_options: EntryFilterOptions = EntryFilterOptions(), # noqa: B008
sort: EntrySortOrder = 'recent',
chunk_size: int | None = None,
Expand Down
2 changes: 0 additions & 2 deletions src/reader/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ def delete_entries(

def get_entries(
self,
now: datetime,
filter_options: EntryFilterOptions,
sort: EntrySortOrder,
limit: int | None,
Expand Down Expand Up @@ -824,7 +823,6 @@ def update(self) -> None:
def search_entries(
self,
query: str,
now: datetime,
filter_options: EntryFilterOptions,
sort: SearchSortOrder,
limit: int | None,
Expand Down
4 changes: 0 additions & 4 deletions src/reader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,9 +1204,7 @@ def get_entries(
if starting_after and sort == 'random':
raise ValueError("using starting_after with sort='random' not supported")

now = self._now()
rv = self._storage.get_entries(
now,
filter_options,
sort,
limit,
Expand Down Expand Up @@ -1797,10 +1795,8 @@ def search_entries(
if starting_after and sort == 'random':
raise ValueError("using starting_after with sort='random' not supported")

now = self._now()
return self._search.search_entries(
query,
now,
filter_options,
sort,
limit,
Expand Down
26 changes: 7 additions & 19 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ def update_search(storage, _, __):


def search_entries_chunk_size_0(storage, _, __):
list(
Search(storage).search_entries_page('entry', datetime(2010, 1, 1), chunk_size=0)
)
list(Search(storage).search_entries_page('entry', chunk_size=0))


def search_entries_chunk_size_1(storage, _, __):
list(
Search(storage).search_entries_page('entry', datetime(2010, 1, 1), chunk_size=1)
)
list(Search(storage).search_entries_page('entry', chunk_size=1))


def search_entry_counts(storage, _, __):
Expand Down Expand Up @@ -97,27 +93,19 @@ def enable_and_update_search(storage):


def iter_search_entries_chunk_size_0(storage):
return Search(storage).search_entries_page(
'entry', datetime(2010, 1, 1), chunk_size=0
)
return Search(storage).search_entries_page('entry', chunk_size=0)


def iter_search_entries_chunk_size_1(storage):
return Search(storage).search_entries_page(
'entry', datetime(2010, 1, 1), chunk_size=1
)
return Search(storage).search_entries_page('entry', chunk_size=1)


def iter_search_entries_chunk_size_2(storage):
return Search(storage).search_entries_page(
'entry', datetime(2010, 1, 1), chunk_size=2
)
return Search(storage).search_entries_page('entry', chunk_size=2)


def iter_search_entries_chunk_size_3(storage):
return Search(storage).search_entries_page(
'entry', datetime(2010, 1, 1), chunk_size=3
)
return Search(storage).search_entries_page('entry', chunk_size=3)


@pytest.mark.slow
Expand Down Expand Up @@ -149,7 +137,7 @@ class ActuallyOK(Exception):

def call_search_entries(search, query):
try:
next(search.search_entries(query, datetime(2010, 1, 1)))
next(search.search_entries(query))
except StopIteration:
raise ActuallyOK

Expand Down
48 changes: 17 additions & 31 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ def delete_entries(storage, feed, entry):


def get_entries_chunk_size_0(storage, _, __):
list(storage.get_entries_page(chunk_size=0, now=datetime(2010, 1, 1)))
list(storage.get_entries_page(chunk_size=0))


def get_entries_chunk_size_1(storage, _, __):
list(storage.get_entries_page(chunk_size=1, now=datetime(2010, 1, 1)))
list(storage.get_entries_page(chunk_size=1))


def get_tags(storage, feed, __):
Expand Down Expand Up @@ -299,7 +299,7 @@ def get_feed_last(storage, feed, __):


def get_entry_last(storage, feed, entry):
storage.get_entry_last(datetime(2010, 1, 1), 'recent', (feed.url, entry.id))
storage.get_entry_last('recent', (feed.url, entry.id))


@pytest.mark.slow
Expand Down Expand Up @@ -402,19 +402,19 @@ def iter_get_feeds_for_update(storage):


def iter_pagination_chunk_size_0(storage):
return storage.get_entries_page(chunk_size=0, now=datetime(2010, 1, 1))
return storage.get_entries_page(chunk_size=0)


def iter_pagination_chunk_size_1(storage):
return storage.get_entries_page(chunk_size=1, now=datetime(2010, 1, 1))
return storage.get_entries_page(chunk_size=1)


def iter_pagination_chunk_size_2(storage):
return storage.get_entries_page(chunk_size=2, now=datetime(2010, 1, 1))
return storage.get_entries_page(chunk_size=2)


def iter_pagination_chunk_size_3(storage):
return storage.get_entries_page(chunk_size=3, now=datetime(2010, 1, 1))
return storage.get_entries_page(chunk_size=3)


def iter_get_tags(storage):
Expand Down Expand Up @@ -533,46 +533,35 @@ def storage_with_two_entries(storage):
@rename_argument('storage', 'storage_with_two_entries')
def test_important_unimportant_by_default(storage):
assert {
e.id
for e in storage.get_entries(
datetime(2010, 1, 1), EntryFilterOptions(important='nottrue')
)
e.id for e in storage.get_entries(EntryFilterOptions(important='nottrue'))
} == {'one', 'two'}


@rename_argument('storage', 'storage_with_two_entries')
def test_important_get_entries(storage):
storage.set_entry_important(('feed', 'one'), True, datetime(2010, 1, 2))

assert {e.id for e in storage.get_entries(now=datetime(2010, 1, 1))} == {
assert {e.id for e in storage.get_entries()} == {
'one',
'two',
}
assert {e.id for e in storage.get_entries(EntryFilterOptions(important='any'))} == {
'one',
'two',
}
assert {
e.id
for e in storage.get_entries(
datetime(2010, 1, 1), EntryFilterOptions(important='any')
)
} == {'one', 'two'}
assert {
e.id
for e in storage.get_entries(
datetime(2010, 1, 1), EntryFilterOptions(important='istrue')
)
e.id for e in storage.get_entries(EntryFilterOptions(important='istrue'))
} == {'one'}
assert {
e.id
for e in storage.get_entries(
datetime(2010, 1, 1), EntryFilterOptions(important='nottrue')
)
e.id for e in storage.get_entries(EntryFilterOptions(important='nottrue'))
} == {'two'}


@rename_argument('storage', 'storage_with_two_entries')
def test_important_entry_important(storage):
storage.set_entry_important(('feed', 'one'), True, None)

assert {e.id: e.important for e in storage.get_entries(datetime(2010, 1, 1))} == {
assert {e.id: e.important for e in storage.get_entries()} == {
'one': True,
'two': None,
}
Expand All @@ -584,10 +573,7 @@ def test_important_mark_as_unimportant(storage):
storage.set_entry_important(('feed', 'one'), False, None)

assert {
e.id
for e in storage.get_entries(
datetime(2010, 1, 1), EntryFilterOptions(important='istrue')
)
e.id for e in storage.get_entries(EntryFilterOptions(important='istrue'))
} == set()


Expand Down

0 comments on commit abf1c1b

Please sign in to comment.