From 38e4996280fd50ba7d5ddc3afc9937db70665d5e Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Thu, 27 Oct 2022 07:33:46 +0200 Subject: [PATCH] Fix the fake revisions after introduction of cache The way I stored it in the linked_revs was the wrong way --- lib/db_revision.py | 5 ++-- lib/importer.py | 58 +++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/lib/db_revision.py b/lib/db_revision.py index 06c3c98..eaebae6 100644 --- a/lib/db_revision.py +++ b/lib/db_revision.py @@ -200,13 +200,12 @@ class DBRevision: return self._files @staticmethod - def requests_to_fetch(db, project, package): + def requests_to_fetch(db): with db.cursor() as cur: cur.execute( """SELECT request_number FROM revisions revs LEFT JOIN requests reqs ON reqs.number=revs.request_number WHERE reqs.id is null AND - revs.request_number IS NOT NULL and project=%s AND package=%s;""", - (project, package), + revs.request_number IS NOT NULL""", ) return [row[0] for row in cur.fetchall()] diff --git a/lib/importer.py b/lib/importer.py index 65adb44..249d5a2 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -181,7 +181,7 @@ class Importer: def find_fake_revisions(self, db): with db.cursor() as cur: cur.execute( - "SELECT * from revisions WHERE id in (SELECT revision_id from linked_revs WHERE considered=FALSE)" + "SELECT * from revisions WHERE id in (SELECT linked_id from linked_revs WHERE considered=FALSE)" ) for row in cur.fetchall(): self._find_fake_revision(db, DBRevision(row)) @@ -268,40 +268,40 @@ class Importer: self.fetch_all_linked_packages(db, project, self.package) # all remaining, no filtering here self.find_linked_revs(db) - self.find_fake_revisions(db) - missing_users = User.missing_users(db) - for userid in missing_users: - missing_user = self.obs.user(userid) - if missing_user: - missing_user.import_into_db(db) + missing_users = User.missing_users(db) + for userid in missing_users: + missing_user = self.obs.user(userid) + if missing_user: + missing_user.import_into_db(db) - for rev in self.revisions_without_files(db): + self.find_fake_revisions(db) + for rev in self.revisions_without_files(db): + with db.cursor() as cur: + cur.execute( + """SELECT unexpanded_srcmd5 from revisions WHERE + id=(SELECT linked_id FROM linked_revs WHERE revision_id=%s)""", + (rev.dbid,), + ) + linked_rev = cur.fetchone() + if linked_rev: + linked_rev = linked_rev[0] + list = self.obs.list( + rev.project, rev.package, rev.unexpanded_srcmd5, linked_rev + ) + if list: + rev.import_dir_list(db, list) + md5 = rev.calculate_files_hash(db) with db.cursor() as cur: cur.execute( - """SELECT unexpanded_srcmd5 from revisions WHERE - id=(SELECT linked_id FROM linked_revs WHERE revision_id=%s)""", - (rev.dbid,), + "UPDATE revisions SET files_hash=%s WHERE id=%s", + (md5, rev.dbid), ) - linked_rev = cur.fetchone() - if linked_rev: - linked_rev = linked_rev[0] - list = self.obs.list( - rev.project, rev.package, rev.unexpanded_srcmd5, linked_rev - ) - if list: - rev.import_dir_list(db, list) - md5 = rev.calculate_files_hash(db) - with db.cursor() as cur: - cur.execute( - "UPDATE revisions SET files_hash=%s WHERE id=%s", - (md5, rev.dbid), - ) - else: - rev.set_broken(db) + else: + rev.set_broken(db) - for number in DBRevision.requests_to_fetch(db, project, self.package): - self.obs.request(number).import_into_db(db) + for number in DBRevision.requests_to_fetch(db): + self.obs.request(number).import_into_db(db) db.conn.commit() TreeBuilder(db).build(self.package)