Skip to content

Commit

Permalink
Merge pull request #3047 from mcalmer/improve-extra-key-handling
Browse files Browse the repository at this point in the history
Improve extra key handling
  • Loading branch information
mcalmer authored Dec 30, 2020
2 parents a135952 + 02b2b47 commit d80310b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
65 changes: 32 additions & 33 deletions backend/server/importlib/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
'suseEula': 'suse_eula_id_seq',
'suseProducts': 'suse_products_id_seq',
'suseSCCRepository': 'suse_sccrepository_id_seq',
'suseProductSCCRepository': 'suse_prdrepo_id_seq',
'rhnPackageExtraTagKey': 'rhn_package_extra_tags_keys_id_seq'
'suseProductSCCRepository': 'suse_prdrepo_id_seq'
}


Expand Down Expand Up @@ -299,40 +298,40 @@ def processCVEs(self, cveHash):
h.executemany(id=toinsert[0], name=toinsert[1])

def processExtraTags(self, extraTags):
query_lookup = """
SELECT id
FROM rhnPackageExtraTagKey
WHERE name = :name
if not extraTags:
return
sql = """
WITH wanted (name) AS (
VALUES %s
)
missing AS (
SELECT nextval('rhn_package_extra_tags_keys_id_seq') AS id, wanted.name
FROM wanted
LEFT JOIN rhnPackageExtraTagKey ON rhnPackageExtraTagKey.name = wanted.name
WHERE rhnPackageExtraTagKey.id IS NULL
)
INSERT INTO rhnPackageExtraTagKey (id, name)
SELECT * from missing
ON CONFLICT DO NOTHING
"""
h_lookup = self.dbmodule.prepare(query_lookup)
toinsert = [[], []]

for name in list(extraTags.keys()):
val = {}
_buildExternalValue(val, { 'name' : name},
self.tables['rhnPackageExtraTagKey'])
h_lookup.execute(name=name)
row = h_lookup.fetchone_dict()
if row:
extraTags[name] = row['id']
continue

# Generate an id
id = self.sequences['rhnPackageExtraTagKey'].next()
extraTags[name] = id

toinsert[0].append(id)
toinsert[1].append(val['name'])

if not toinsert[0]:
# Nothing to do
values = [key for key in extraTags.keys() if key != '']
if not values:
return
h = self.dbmodule.prepare(sql)
r = h.execute_values(sql, values, fetch=False)

query_insert = """
INSERT INTO rhnPackageExtraTagKey (id, name)
VALUES (:id, :name)"""
h_insert = self.dbmodule.prepare(query_insert)
h_insert.executemany(id=toinsert[0], name=toinsert[1])
sql = """
WITH wanted (name) AS (
VALUES %s
)
SELECT wanted.id, wanted.name
FROM wanted
JOIN rhnPackageExtraTagKey ON rhnPackageExtraTagKey.name = wanted.name
"""
h = self.dbmodule.prepare(sql)
tags = h.execute_values(sql, values)
for tag in tags:
extraTags[tag[1]] = tag[0]

def lookupErrataFileTypes(self, hash):
hash.clear()
Expand Down
8 changes: 0 additions & 8 deletions backend/server/importlib/backendOracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,6 @@ class OracleBackend(Backend):
pk = ['package_id', 'eula_id'],
attribute = 'eulas',
),
Table('rhnPackageExtraTagKey',
fields={
'id' : DBint(),
'name' : DBstring(256),
},
pk=['id'],
attribute='extra_tags',
),
Table('rhnPackageExtraTag',
fields={
'package_id' : DBint(),
Expand Down
1 change: 1 addition & 0 deletions backend/server/rhnServer/server_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def processPackageKeyAssociations(header, checksum_type, checksum):
insert into rhnPackagekey
(id, key_id, key_type_id) values
(sequence_nextval('rhn_pkey_id_seq'), :key_id, :key_type_id)
on conflict do nothing
""")

lookup_keyid_sql = rhnSQL.prepare("""
Expand Down
1 change: 1 addition & 0 deletions backend/spacewalk-backend.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- harden extratag key import by execute_values to ignore conflicts
- internal code cleanup (dropping unused table rhnErrataTmp)
- Fix Debian package version comparison
- Removal of python-gzipstream since it's no longer used
Expand Down

0 comments on commit d80310b

Please sign in to comment.