From 17737f69f21a9eafb15b21ce2fc5873fe393be69 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 6 Jul 2026 12:30:36 -0400 Subject: [PATCH 1/2] refactor(tags): stop re-binding invariant query parameters Signed-off-by: Josh --- lib/private/Tags.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/private/Tags.php b/lib/private/Tags.php index abe68819af3f9..e2d6231b2577e 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -159,16 +159,16 @@ public function getTagsForObjects(array $objIds) { ->where($qb->expr()->eq('uid', $qb->createParameter('uid'))) ->andWhere($qb->expr()->eq('r.type', $qb->createParameter('type'))) ->andWhere($qb->expr()->in('objid', $qb->createParameter('chunk'))); + + $qb->setParameter('uid', $this->user, IQueryBuilder::PARAM_STR); + $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); + foreach ($chunks as $chunk) { - $qb->setParameter('uid', $this->user, IQueryBuilder::PARAM_STR); - $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); $qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY); $result = $qb->executeQuery(); while ($row = $result->fetch()) { $objId = (int)$row['objid']; - if (!isset($entries[$objId])) { - $entries[$objId] = []; - } + $entries[$objId] ??= []; $entries[$objId][] = $row['category']; } $result->closeCursor(); @@ -393,19 +393,25 @@ protected function save(): void { // reload tags to get the proper ids. $this->tags = $this->mapper->loadTags($this->owners, $this->type); $this->logger->debug(__METHOD__ . 'tags' . print_r($this->tags, true), ['app' => 'core']); + + $qb = $this->db->getQueryBuilder(); + $qb->insert(self::RELATION_TABLE) + ->values([ + 'objid' => $qb->createParameter('objid'), + 'categoryid' => $qb->createParameter('categoryid'), + 'type' => $qb->createParameter('type'), + ]); + // Loop through temporarily cached objectid/tagname pairs // and save relations. foreach ($this->relations as $relation) { $tagId = $this->getTagId($relation['tag']); $this->logger->debug(__METHOD__ . 'catid ' . $relation['tag'] . ' ' . $tagId, ['app' => 'core']); if ($tagId) { - $qb = $this->db->getQueryBuilder(); - $qb->insert(self::RELATION_TABLE) - ->values([ - 'objid' => $qb->createNamedParameter($relation['objid'], IQueryBuilder::PARAM_INT), - 'categoryid' => $qb->createNamedParameter($tagId, IQueryBuilder::PARAM_INT), - 'type' => $qb->createNamedParameter($this->type), - ]); + $qb->setParameter('objid', $relation['objid'], IQueryBuilder::PARAM_INT); + $qb->setParameter('categoryid', $tagId, IQueryBuilder::PARAM_INT); + $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); + try { $qb->executeStatement(); } catch (Exception $e) { From 8eef9cf38988866a3d21f58d65f0a69b842df465 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 6 Jul 2026 12:37:32 -0400 Subject: [PATCH 2/2] refactor(tags): move invariant parameter binding out of loop in save Signed-off-by: Josh --- lib/private/Tags.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/Tags.php b/lib/private/Tags.php index e2d6231b2577e..d763e7e6aa099 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -402,6 +402,8 @@ protected function save(): void { 'type' => $qb->createParameter('type'), ]); + $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); + // Loop through temporarily cached objectid/tagname pairs // and save relations. foreach ($this->relations as $relation) { @@ -410,7 +412,6 @@ protected function save(): void { if ($tagId) { $qb->setParameter('objid', $relation['objid'], IQueryBuilder::PARAM_INT); $qb->setParameter('categoryid', $tagId, IQueryBuilder::PARAM_INT); - $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); try { $qb->executeStatement();