Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Dump file is growing unsustainably fixes 394 #404

Merged
merged 9 commits into from
Apr 20, 2018
Merged

Dump file is growing unsustainably fixes 394 #404

merged 9 commits into from
Apr 20, 2018

Conversation

peterbe
Copy link
Contributor

@peterbe peterbe commented Apr 13, 2018

No description provided.

@peterbe peterbe requested a review from leplatrem April 18, 2018 13:57
)
# XXX Not sure why this needs to be a "quotation mark"
# encoded thing
previous_run_timestamp = '"%s"' % highest_timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ETag header is the timestamp between quotes (?_since="1234").
Maybe you could rename the variable to previous_run_etag instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it as per your suggestion.

with open(self.cache_file) as f:
records = json.load(f)
assert len(records) == 1
assert records['a'][0] == 2 # [0] is last modified
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not feel like you test the migration here. Add another record not returned in get_records() to assert that previous entries were migrated too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my updated commit. Better?

@peterbe
Copy link
Contributor Author

peterbe commented Apr 18, 2018

@leplatrem Can you look over the latest commits after you approved.

The reason it was failing was because the unit tests were leaking. Their ordered mattered whether the tests would pass or if one would fail.

def record_unchanged(record):
return (
record['id'] in existing and
existing.get(record['id']) == hash_record(record)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since hash_record() never returns None, you can write:

return existing.get(record['id']) == hash_record(record)

and thus even maybe drop the use of this record_unchanged() function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if I do that I have to execute hash_record(record) just so that it can ultimately become: if None == 'somehashstringhere':.

The first part of the if helps figure out if it's worth bothering calculating a hash. By doing both things the if statement becomes (if you break it down in steps): if False and existing.get(record['id']) == hash_record(record): which means it exists out on the first False and doesn't bother executing the existing.get(record['id']) == hash_record(record) part at all.

Right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

# The migration is done, but let's make sure the fetch_existing
# continues to work as expected.
mocked.get_records.return_value = [
{'id': 'a', 'title': 'b', 'last_modified': 2},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the migration is done, I suppose it should use the latest Etag, and this record does not seem unchanged, so it should not be listed here.

In order to test that the entries present in the old cache effectively end up in the new cache, it would make sense not to list this record here, so that when you make sure it is present at the end, you know it's taken from the old cache file

@peterbe peterbe merged commit dd361a3 into mozilla-services:master Apr 20, 2018
@peterbe peterbe deleted the dump-file-is-growing-unsustainably-fixes-394 branch April 20, 2018 11:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants