Skip to content

Commit

Permalink
Rename Entry.first_updated to Entry.added.
Browse files Browse the repository at this point in the history
For #239/#183.
  • Loading branch information
lemon24 committed Oct 22, 2021
1 parent 4c2e071 commit c7874c5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/reader/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,9 +1379,9 @@ def make_get_entries_query(
entries.important
entries.important_modified
entries.first_updated
entries.added_by
entries.last_updated
entries.original_feed
entries.added_by
""".split()
)
.FROM("entries")
Expand Down Expand Up @@ -1415,8 +1415,8 @@ def entry_factory(t: Tuple[Any, ...]) -> Entry:
t[24],
t[25],
t[26],
t[27] or feed.url,
t[28],
t[27],
t[28] or feed.url,
feed,
)
return Entry._make(entry)
Expand Down
2 changes: 1 addition & 1 deletion src/reader/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class EntryUpdateIntent(NamedTuple):
#: in update_feed, the start of each feed update in update_feeds).
last_updated: datetime

#: First last_updated.
#: First last_updated (sets Entry.added).
#: None if the entry already exists.
first_updated: Optional[datetime]

Expand Down
4 changes: 3 additions & 1 deletion src/reader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ def _update_feeds(
# for the second of two new feeds updated in the same update_feeds()
# call, first_updated_epoch != last_updated.
#
# Update: However, added == last_updated for the first update.
#
global_now = self._now()

# Excluding the special exception handling,
Expand Down Expand Up @@ -1128,7 +1130,7 @@ def get_entries(
rv_entry,
'updated',
'published',
'first_updated',
'added',
'last_updated',
'read_modified',
'important_modified',
Expand Down
22 changes: 11 additions & 11 deletions src/reader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,17 @@ def feed_url(self) -> str:
#: .. versionadded:: 2.2
important_modified: Optional[datetime] = None

#: The date when the entry was first updated (added) by reader.
#: The date when the entry was added (first updated) to reader.
#:
#: .. versionadded:: 2.5
first_updated: datetime = cast(datetime, None)
added: datetime = cast(datetime, None)

#: The source of the entry. One of ``'feed'``, ``'user'``.
#:
#: Other values may be added in the future.
#:
#: .. versionadded:: 2.5
added_by: EntryAddedBy = cast(EntryAddedBy, None)

#: The date when the entry was last updated by reader.
#:
Expand All @@ -297,13 +304,6 @@ def feed_url(self) -> str:
# we don't check for it in __post_init__ because it's still useful
# to have it None in tests. The cast is to please mypy.

#: The source of the entry. One of ``'feed'``, ``'user'``.
#:
#: Other values may be added in the future.
#:
#: .. versionadded:: 2.5
added_by: EntryAddedBy = cast(EntryAddedBy, None)

#: The entry's feed.
feed: Feed = cast(Feed, None)

Expand All @@ -321,13 +321,13 @@ def updated_not_none(self) -> datetime:
"""Like :attr:`updated`, but guaranteed to be set (not None).
If the entry `updated` is missing in the feed,
defaults to when the entry was first added (`first_updated`).
defaults to when the entry was first `added`.
.. versionadded:: 2.0
Identical to the behavior of :attr:`updated` before 2.0.
"""
return self.updated or self.first_updated
return self.updated or self.added


@dataclass(frozen=True)
Expand Down
68 changes: 34 additions & 34 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_update_feed_updated(reader, call_update_method, caplog):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
)
}
Expand All @@ -96,12 +96,12 @@ def test_update_feed_updated(reader, call_update_method, caplog):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
entry_two.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
),
}
Expand Down Expand Up @@ -141,17 +141,17 @@ def test_update_feed_updated(reader, call_update_method, caplog):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
entry_two.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
),
entry_three.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 4),
added=datetime(2010, 1, 4),
last_updated=datetime(2010, 1, 4),
),
}
Expand All @@ -175,17 +175,17 @@ def test_update_feed_updated(reader, call_update_method, caplog):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
entry_two.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
),
entry_three.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 4),
added=datetime(2010, 1, 4),
last_updated=datetime(2010, 1, 4),
),
}
Expand All @@ -206,22 +206,22 @@ def test_update_feed_updated(reader, call_update_method, caplog):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
entry_two.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
),
entry_three.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 4),
added=datetime(2010, 1, 4),
last_updated=datetime(2010, 1, 4),
),
entry_four.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 5),
added=datetime(2010, 1, 5),
last_updated=datetime(2010, 1, 5),
),
}
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_update_entry_updated(reader, call_update_method, caplog, monkeypatch):
assert set(reader.get_entries()) == {
old_entry.as_entry(
feed=feed,
first_updated=datetime(2010, 2, 2),
added=datetime(2010, 2, 2),
last_updated=datetime(2010, 2, 2),
)
}
Expand All @@ -275,7 +275,7 @@ def test_update_entry_updated(reader, call_update_method, caplog, monkeypatch):
assert set(reader.get_entries()) == {
old_entry.as_entry(
feed=feed,
first_updated=datetime(2010, 2, 2),
added=datetime(2010, 2, 2),
last_updated=datetime(2010, 2, 2),
)
}
Expand All @@ -298,7 +298,7 @@ def test_update_entry_updated(reader, call_update_method, caplog, monkeypatch):
assert set(reader.get_entries()) == {
new_entry.as_entry(
feed=feed,
first_updated=datetime(2010, 2, 2),
added=datetime(2010, 2, 2),
last_updated=datetime(2010, 2, 3, 12),
)
}
Expand All @@ -318,7 +318,7 @@ def test_update_entry_updated(reader, call_update_method, caplog, monkeypatch):
assert set(reader.get_entries()) == {
new_entry.as_entry(
feed=feed,
first_updated=datetime(2010, 2, 2),
added=datetime(2010, 2, 2),
last_updated=datetime(2010, 2, 4),
)
}
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_update_no_updated(reader, chunk_size, call_update_method):
entry_one.as_entry(
feed=feed,
updated=None,
first_updated=datetime(2010, 1, 1),
added=datetime(2010, 1, 1),
last_updated=datetime(2010, 1, 1),
)
}
Expand All @@ -381,12 +381,12 @@ def test_update_no_updated(reader, chunk_size, call_update_method):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 1),
added=datetime(2010, 1, 1),
last_updated=datetime(2010, 1, 2),
),
entry_two.as_entry(
feed=feed,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
}
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_update_new(reader):
assert set(reader.get_entries()) == {
entry_two.as_entry(
feed=two,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
)
}
Expand All @@ -502,12 +502,12 @@ def test_update_new(reader):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=one,
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
),
entry_two.as_entry(
feed=two,
first_updated=datetime(2010, 1, 2),
added=datetime(2010, 1, 2),
last_updated=datetime(2010, 1, 2),
),
}
Expand Down Expand Up @@ -899,7 +899,7 @@ def test_update_feed(reader, feed_arg):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=one,
first_updated=datetime(2010, 1, 1),
added=datetime(2010, 1, 1),
last_updated=datetime(2010, 1, 1),
)
}
Expand All @@ -912,12 +912,12 @@ def test_update_feed(reader, feed_arg):
assert set(reader.get_entries()) == {
entry_one.as_entry(
feed=one,
first_updated=datetime(2010, 1, 1),
added=datetime(2010, 1, 1),
last_updated=datetime(2010, 1, 1),
),
entry_two.as_entry(
feed=two,
first_updated=datetime(2010, 1, 1),
added=datetime(2010, 1, 1),
last_updated=datetime(2010, 1, 1),
),
}
Expand Down Expand Up @@ -1292,7 +1292,7 @@ def test_get_entries_recent_first_updated_order(
reader, chunk_size, pre_stuff, call_method
):
"""For entries with no published/updated,
entries should be sorted by first_updated.
entries should be sorted by added.
"""
reader._storage.chunk_size = chunk_size
Expand Down Expand Up @@ -1501,10 +1501,10 @@ def test_add_remove_get_feeds(reader, feed_arg):
one = one.as_feed(added=datetime(2010, 1, 1), last_updated=datetime(2010, 1, 2))
two = two.as_feed(added=datetime(2010, 1, 1), last_updated=datetime(2010, 1, 2))
entry_one = entry_one.as_entry(
feed=one, first_updated=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 2)
feed=one, added=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 2)
)
entry_two = entry_two.as_entry(
feed=two, first_updated=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 2)
feed=two, added=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 2)
)

assert set(reader.get_feeds()) == {one, two}
Expand Down Expand Up @@ -1679,7 +1679,7 @@ def test_data_roundtrip(reader):
feed=feed.as_feed(
added=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 3)
),
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
)
]
Expand Down Expand Up @@ -1774,7 +1774,7 @@ class datetime_mock(datetime):
fix_datetime_tzinfo(
e.as_entry(
feed=feed,
first_updated=utc_datetime(2010, 1, 2),
added=utc_datetime(2010, 1, 2),
last_updated=utc_datetime(2010, 1, 2),
),
'updated',
Expand Down Expand Up @@ -1846,7 +1846,7 @@ def test_get_entry(reader, entry_arg):
feed=feed.as_feed(
added=datetime(2010, 1, 2), last_updated=datetime(2010, 1, 3)
),
first_updated=datetime(2010, 1, 3),
added=datetime(2010, 1, 3),
last_updated=datetime(2010, 1, 3),
)
assert reader.get_entry(entry_arg(entry)) == entry
Expand Down Expand Up @@ -2994,12 +2994,12 @@ def test_entry_counts(reader, kwargs, expected, pre_stuff, call_method, rv_type)
parser.entry(2, 3, datetime(2011, 5, 15), enclosures=[]),
# important
parser.entry(2, 4, datetime(2011, 8, 15), enclosures=[]),
# not deduped with 4, because (published, updated, first_updated) don't overlap
# not deduped with 4, because (published, updated, added) don't overlap
parser.entry(
2, 5, datetime(2011, 9, 15), enclosures=[], published=datetime(2011, 8, 15)
),
parser.entry(2, 6, datetime(2011, 11, 15), enclosures=[]),
# gets updated / first_updated 2011-12-16 (_now() during update_feeds())
# gets updated / added 2011-12-16 (_now() during update_feeds())
parser.entry(2, 7, None, enclosures=[]),
# important, read
parser.entry(2, 8, datetime(2011, 12, 15), enclosures=[]),
Expand Down

0 comments on commit c7874c5

Please sign in to comment.