Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/archiver/storage.py
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | def content_archive_get(self, content_id, cur=None): | ||||
Yields: | Yields: | ||||
A tuple (content_id, present_copies, ongoing_copies), where | A tuple (content_id, present_copies, ongoing_copies), where | ||||
ongoing_copies is a dict mapping copy to mtime. | ongoing_copies is a dict mapping copy to mtime. | ||||
""" | """ | ||||
return self.db.content_archive_get(content_id, cur) | return self.db.content_archive_get(content_id, cur) | ||||
@db_transaction_generator | @db_transaction_generator | ||||
def content_archive_get_copies(self, previous_content=None, limit=1000, | def content_archive_get_copies(self, last_content=None, limit=1000, | ||||
cur=None): | cur=None): | ||||
"""Get the list of copies for `limit` contents starting after | """ Get the list of copies for `limit` contents starting after | ||||
`previous_content`. | `last_content`. | ||||
Args: | Args: | ||||
previous_content: sha1 of the last content retrieved. May be None | last_content: sha1 of the last content retrieved. May be None | ||||
to start at the beginning. | to start at the beginning. | ||||
limit: number of contents to retrieve. Can be None to retrieve all | limit: number of contents to retrieve. Can be None to retrieve all | ||||
objects (will be slow). | objects (will be slow). | ||||
Yields: | Yields: | ||||
A tuple (content_id, present_copies, ongoing_copies), where | A tuple (content_id, present_copies, ongoing_copies), where | ||||
ongoing_copies is a dict mapping copy to mtime. | ongoing_copies is a dict mapping copy to mtime. | ||||
""" | """ | ||||
yield from self.db.content_archive_get_copies(previous_content, limit, | yield from self.db.content_archive_get_copies(last_content, limit, | ||||
cur) | cur) | ||||
@db_transaction_generator | |||||
def content_archive_get_unarchived_copies( | |||||
self, retention_policy, last_content=None, | |||||
limit=1000, cur=None): | |||||
zack: - "starting after" -> "starting at"
- you should specify if previous_content is included or… | |||||
Done Inline ActionsWon't the term offset be misleading about the type of the variable ? As the current previous_content variable is a sha1, and offset may sound like an integer. qcampos: Won't the term //offset// be misleading about the type of the variable ? As the current… | |||||
Done Inline ActionsGood point. zack: Good point.
Then, as a last change (pun, intended), I propose to rename "previous_content" to… | |||||
""" Get the list of copies for `limit` contents starting after | |||||
`last_content`. Yields only copies with number of present | |||||
smaller than `retention policy`. | |||||
Args: | |||||
last_content: sha1 of the last content retrieved. May be None | |||||
to start at the beginning. | |||||
retention_policy: number of presentcopies required. | |||||
limit: number of contents to retrieve. Can be None to retrieve all | |||||
objects (will be slow). | |||||
Yields: | |||||
A tuple (content_id, present_copies, ongoing_copies), where | |||||
ongoing_copies is a dict mapping copy to mtime. | |||||
""" | |||||
yield from self.db.content_archive_get_unarchived_copies( | |||||
retention_policy, last_content, limit, cur) | |||||
@db_transaction | @db_transaction | ||||
def content_archive_update(self, content_id, archive_id, | def content_archive_update(self, content_id, archive_id, | ||||
new_status=None, cur=None): | new_status=None, cur=None): | ||||
""" Update the status of an archive content and set its mtime to now | """ Update the status of an archive content and set its mtime to now | ||||
Change the mtime of an archived content for the given archive and set | Change the mtime of an archived content for the given archive and set | ||||
it's mtime to the current time. | it's mtime to the current time. | ||||
Show All 9 Lines |
More generally, I suggest to use a more consist terminology for pagination: the SQL LIMIT/OFFSET paradigm seems to be a good example to follow here. How about: limit=1000, offset=None (i.e., also dropping the trailing "_content" from the offset argument)?