Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import random | import random | ||||
import select | import select | ||||
from swh.core.db import BaseDb | from swh.core.db import BaseDb | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | class Db(BaseDb): | ||||
content_add_keys = content_get_metadata_keys + ['ctime'] | content_add_keys = content_get_metadata_keys + ['ctime'] | ||||
skipped_content_keys = [ | skipped_content_keys = [ | ||||
'sha1', 'sha1_git', 'sha256', 'blake2s256', | 'sha1', 'sha1_git', 'sha256', 'blake2s256', | ||||
'length', 'reason', 'status', 'origin'] | 'length', 'reason', 'status', 'origin'] | ||||
def content_get_metadata_from_sha1s(self, sha1s, cur=None): | def content_get_metadata_from_sha1s(self, sha1s, cur=None): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
yield from execute_values_generator( | yield from execute_values_generator( | ||||
cur, """ | cur, """ | ||||
select t.sha1, %s from (values %%s) as t (sha1) | select t.sha1, %s from (values %%s) as t (sha1) | ||||
left join content using (sha1) | inner join content using (sha1) | ||||
""" % ', '.join(self.content_get_metadata_keys[1:]), | """ % ', '.join(self.content_get_metadata_keys[1:]), | ||||
((sha1,) for sha1 in sha1s), | ((sha1,) for sha1 in sha1s), | ||||
) | ) | ||||
def content_get_range(self, start, end, limit=None, cur=None): | def content_get_range(self, start, end, limit=None, cur=None): | ||||
"""Retrieve contents within range [start, end]. | """Retrieve contents within range [start, end]. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 866 Lines • Show Last 20 Lines |