Skip to content

Commit

Permalink
Reduce the number of queries in the Errata scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
mprahl committed Jul 18, 2019
1 parent 70b5799 commit a316e92
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions scrapers/errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,8 @@ def update_neo4j(self, advisories):
and build.__label__ == ContainerKojiBuild.__label__:
adv.add_label(ContainerAdvisory.__label__)

nvr = '-'.join((associated_build['name'], associated_build['version'],
associated_build['release']))

sql = """\
SELECT created_at
FROM Errata_public.errata_brew_mappings
INNER JOIN Errata_public.brew_builds
ON Errata_public.errata_brew_mappings.brew_build_id
= Errata_public.brew_builds.id
WHERE errata_id = {0} AND current = 1 AND nvr = '{1}';
""".format(advisory['id'], nvr)
log.info('Getting the time build {0} was added to advisory {1}'.format(
nvr, advisory['id']))
time_attached_result = self.teiid.query(sql)
if time_attached_result:
time_attached = time_attached_result[0].get('created_at')
else:
time_attached = None

attached_rel = adv.attached_builds.relationship(build)
time_attached = associated_build['time_attached']
if attached_rel:
if attached_rel.time_attached != time_attached:
adv.attached_builds.replace(build, {'time_attached': time_attached})
Expand Down Expand Up @@ -199,7 +181,7 @@ def get_associated_builds(self, advisory_id):
"""
sql = """\
SELECT brew_builds.id as id_, packages.name, brew_builds.release, removed_index_id,
brew_builds.version
brew_builds.version, brew_mappings.created_at as time_attached
FROM Errata_public.errata_brew_mappings as brew_mappings
LEFT JOIN Errata_public.brew_builds AS brew_builds
ON brew_builds.id = brew_mappings.brew_build_id
Expand Down

0 comments on commit a316e92

Please sign in to comment.