Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] use updatemany in TransformationDB #7898

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/DIRAC/TransformationSystem/DB/TransformationDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,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 @@ -738,12 +737,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 @@ -801,11 +797,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
Loading