Skip to content

Commit

Permalink
fix: use updatemany in TransformationDB
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Nov 19, 2024
1 parent d834c6c commit a61886d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/DIRAC/TransformationSystem/DB/TransformationDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ def _getTransformationID(self, transName, connection=False):
return S_OK(res["Value"][0][0])

def __deleteTransformation(self, transID, connection=False):
req = "DELETE FROM Transformations WHERE TransformationID=%d;" % 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."""
Expand Down Expand Up @@ -737,12 +736,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)

Expand Down Expand Up @@ -800,11 +796,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
Expand Down

0 comments on commit a61886d

Please sign in to comment.