bitbake: prserv: import simplification

Simplify the importone() hook:
- to make it independent from the "history" mode which is
  client specific.
- remove the "history" parameter
- we want all values to be imported for binary
  reproducibility purposes.
- using the store_value() function (which warrants
  you don't save the same value twice and doesn't write
  when you're using a read-only server) is enough.

(Bitbake rev: 000704a53470ab1ead840403b5531f22ebf1fd49)

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Cc: Joshua Watt <JPEWhacker@gmail.com>
Cc: Tim Orling <ticotimo@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Michael Opdenacker 2024-05-11 16:31:34 +05:30 committed by Richard Purdie
parent 3be2201de5
commit ae0725577d
3 changed files with 6 additions and 65 deletions

View File

@ -42,9 +42,9 @@ class PRAsyncClient(bb.asyncrpc.AsyncClient):
if response:
return response["value"]
async def importone(self, version, pkgarch, checksum, value, history=False):
async def importone(self, version, pkgarch, checksum, value):
response = await self.invoke(
{"import-one": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "value": value, "history": history}}
{"import-one": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "value": value}}
)
if response:
return response["value"]

View File

@ -192,67 +192,9 @@ class PRTable(object):
self.store_value(version, pkgarch, checksum, value)
return value
def _import_hist(self, version, pkgarch, checksum, value):
if self.read_only:
return None
val = None
with closing(self.conn.cursor()) as cursor:
data = cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row = data.fetchone()
if row is not None:
val=row[0]
else:
#no value found, try to insert
try:
cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
(version, pkgarch, checksum, value))
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
self.conn.commit()
data = cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row = data.fetchone()
if row is not None:
val = row[0]
return val
def _import_no_hist(self, version, pkgarch, checksum, value):
if self.read_only:
return None
with closing(self.conn.cursor()) as cursor:
try:
#try to insert
cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
(version, pkgarch, checksum, value))
except sqlite3.IntegrityError as exc:
#already have the record, try to update
try:
cursor.execute("UPDATE %s SET value=? WHERE version=? AND pkgarch=? AND checksum=? AND value<?"
% (self.table),
(value, version, pkgarch, checksum, value))
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
self.conn.commit()
data = cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=? AND value>=?;" % self.table,
(version, pkgarch, checksum, value))
row=data.fetchone()
if row is not None:
return row[0]
else:
return None
def importone(self, version, pkgarch, checksum, value, history=False):
if history:
return self._import_hist(version, pkgarch, checksum, value)
else:
return self._import_no_hist(version, pkgarch, checksum, value)
def importone(self, version, pkgarch, checksum, value):
self.store_value(version, pkgarch, checksum, value)
return value
def export(self, version, pkgarch, checksum, colinfo, history=False):
metainfo = {}

View File

@ -179,9 +179,8 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection):
pkgarch = request["pkgarch"]
checksum = request["checksum"]
value = request["value"]
history = request["history"]
value = self.server.table.importone(version, pkgarch, checksum, value, history)
value = self.server.table.importone(version, pkgarch, checksum, value)
if value is not None:
response = {"value": value}