From 58a3d5cc0e299f0bc54692670d95bdbc38ed4b02 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Fri, 13 Dec 2024 15:46:21 +0100 Subject: [PATCH] sweep: #7898 use updatemany in TransformationDB --- .../DB/TransformationDB.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/DIRAC/TransformationSystem/DB/TransformationDB.py b/src/DIRAC/TransformationSystem/DB/TransformationDB.py index 78a50f8b389..a08c95669ed 100755 --- a/src/DIRAC/TransformationSystem/DB/TransformationDB.py +++ b/src/DIRAC/TransformationSystem/DB/TransformationDB.py @@ -426,8 +426,7 @@ def _getTransformationID(self, transName, connection=False): return S_OK(res["Value"][0][0]) def __deleteTransformation(self, transID, connection=False): - req = f"DELETE FROM Transformations WHERE TransformationID={transID};" - return self._update(req, conn=connection) + return self._update(f"DELETE FROM Transformations WHERE TransformationID={transID};", conn=connection) def __updateFilterQueries(self, connection=False): """Get filters for all defined input streams in all the transformations.""" @@ -724,12 +723,9 @@ def __addFilesToTransformation(self, transID, fileIDs, connection=False): fileIDs.remove(tupleIn[0]) if not fileIDs: return S_OK([]) - req = "INSERT INTO TransformationFiles (TransformationID,FileID,LastUpdate,InsertedTime) VALUES" - for fileID in fileIDs: - req = "%s (%d,%d,UTC_TIMESTAMP(),UTC_TIMESTAMP())," % (req, transID, fileID) - req = req.rstrip(",") - res = self._update(req, conn=connection) - if not res["OK"]: + values = [(transID, fileID) for fileID in fileIDs] + req = "INSERT INTO TransformationFiles (TransformationID,FileID,LastUpdate,InsertedTime) VALUES (%s, %s, UTC_TIMESTAMP(), UTC_TIMESTAMP())" + if not (res := self._updatemany(req, values, conn=connection))["OK"]: return res return S_OK(fileIDs) @@ -779,11 +775,9 @@ def __assignTransformationFile(self, transID, taskID, se, fileIDs, connection=Fa res = self._update(req, conn=connection) if not res["OK"]: gLogger.error("Failed to assign file to task", res["Message"]) - fileTuples = [] - for fileID in fileIDs: - fileTuples.append("(%d,%d,%d)" % (transID, fileID, taskID)) - req = f"INSERT INTO TransformationFileTasks (TransformationID,FileID,TaskID) VALUES {','.join(fileTuples)}" - res = self._update(req, conn=connection) + values = [(transID, fileID, taskID) for fileID in fileIDs] + req = "INSERT INTO TransformationFileTasks (TransformationID,FileID,TaskID) VALUES (%s, %s, %s)" + res = self._updatemany(req, values, conn=connection) if not res["OK"]: gLogger.error("Failed to assign file to task", res["Message"]) return res