-
Notifications
You must be signed in to change notification settings - Fork 9
Fix BibliographicData.has_changed to throttle updates when data sourc… #3198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f262588
7d248f4
231a9ea
27d7613
8779a55
24c5aa0
6e690b0
cc7adea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import datetime | ||
| from functools import partial | ||
| from typing import Any | ||
| from unittest.mock import MagicMock | ||
|
|
@@ -559,3 +560,18 @@ def test_internal_formats(self) -> None: | |
| # An unrecognized format does not correspond to any delivery | ||
| # mechanisms. | ||
| assert internal_formats("no-such-format") == [] | ||
|
|
||
| def test_book_info_to_bibliographic_sets_minimum_time_between_updates( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test does get at verifying that this change is affecting OverDrive books, but it would be nice to see the behavior difference in a more integrated way in I was thinking something there with a shape like: @pytest.mark.parametrize(
"is_overdrive, edition_age, expected",
[
pytest.param(
False,
datetime.timedelta(seconds=1),
True,
id="default-minimum-always-reimports",
),
pytest.param(
True,
datetime.timedelta(days=1),
False,
id="overdrive-within-cooldown-skips",
),
pytest.param(
True,
datetime.timedelta(days=4),
True,
id="overdrive-outside-cooldown-reimports",
),
],
)
def test_has_changed_no_source_timestamp(
self,
db: DatabaseTransactionFixture,
is_overdrive: bool,
edition_age: datetime.timedelta,
expected: bool,
):
now = utc_now()
edition = db.edition()
edition.updated_at = now - edition_age
data_source_name = DataSource.OVERDRIVE if is_overdrive else edition.data_source.name
bibliographic = BibliographicData(
data_source_name=data_source_name,
data_source_last_updated=None,
)
with freeze_time(now):
assert bibliographic.has_changed(db.session, edition=edition) is expected
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm missing you @tdilauro: I'm probably being dense. I'll ping you on slack and maybe we can jump on a short call.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether the DS is overdrive or not has no bearing on the expected functionality of the has_changed method. The difference is driven by the presence of a min time btw updates. |
||
| self, overdrive_api_fixture: OverdriveAPIFixture | ||
| ): | ||
| """book_info_to_bibliographic sets a non-zero minimum_time_between_updates. | ||
|
|
||
| Overdrive does not supply a data_source_last_updated timestamp, so without | ||
| a minimum update interval every record would be re-imported on every run. | ||
| The extractor sets a 3-day cooldown to prevent that churn. | ||
| """ | ||
| raw, info = overdrive_api_fixture.sample_json("overdrive_metadata.json") | ||
| metadata = OverdriveRepresentationExtractor.book_info_to_bibliographic(info) | ||
|
|
||
| assert metadata is not None | ||
| assert metadata.minimum_time_between_updates == datetime.timedelta(days=3) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably update the docstring here temporarily, since it doesn't accurately reflect the current situation.