From f1461b720c167cd661ac2680c6607d630e1530ac Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 23 Mar 2023 18:12:39 -0700 Subject: [PATCH] More refactor Signed-off-by: Varun Patil --- lib/Db/TimelineQueryLivePhoto.php | 5 +---- lib/Db/TimelineQueryMap.php | 4 +--- lib/Db/TimelineQuerySingleItem.php | 4 +--- lib/Db/TimelineWritePlaces.php | 9 ++++++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/Db/TimelineQueryLivePhoto.php b/lib/Db/TimelineQueryLivePhoto.php index bd28f542..d06112da 100644 --- a/lib/Db/TimelineQueryLivePhoto.php +++ b/lib/Db/TimelineQueryLivePhoto.php @@ -16,10 +16,7 @@ trait TimelineQueryLivePhoto $qb->expr()->eq('lp.liveid', 'm.liveid'), )) ; - $result = $qb->executeQuery(); - $row = $result->fetch(); - $result->closeCursor(); - return $row; + return $qb->executeQuery()->fetch(); } } diff --git a/lib/Db/TimelineQueryMap.php b/lib/Db/TimelineQueryMap.php index e23fde17..25e2567a 100644 --- a/lib/Db/TimelineQueryMap.php +++ b/lib/Db/TimelineQueryMap.php @@ -62,9 +62,7 @@ trait TimelineQueryMap $this->transformMapBoundsFilter($query, false, $bounds, 'c'); // Execute query - $cursor = $this->executeQueryWithCTEs($query); - $res = $cursor->fetchAll(); - $cursor->closeCursor(); + $res = $this->executeQueryWithCTEs($query)->fetchAll(); // Post-process results $clusters = []; diff --git a/lib/Db/TimelineQuerySingleItem.php b/lib/Db/TimelineQuerySingleItem.php index 46da1a68..d50cc9c1 100644 --- a/lib/Db/TimelineQuerySingleItem.php +++ b/lib/Db/TimelineQuerySingleItem.php @@ -40,9 +40,7 @@ trait TimelineQuerySingleItem $qb->addSelect('exif'); } - $result = $qb->executeQuery(); - $row = $result->fetch(); - $result->closeCursor(); + $row = $qb->executeQuery()->fetch(); $utcTs = 0; diff --git a/lib/Db/TimelineWritePlaces.php b/lib/Db/TimelineWritePlaces.php index 8e74a7ce..86c77c71 100644 --- a/lib/Db/TimelineWritePlaces.php +++ b/lib/Db/TimelineWritePlaces.php @@ -65,10 +65,11 @@ trait TimelineWritePlaces $sql = str_replace('*PREFIX*memories_planet_geometry', 'memories_planet_geometry', $query->getSQL()); // Run query - $result = $this->connection->executeQuery($sql); - $rows = $result->fetchAll(); + $rows = $this->connection->executeQuery($sql)->fetchAll(); + + // Insert records in transaction + $this->connection->beginTransaction(); - // Insert records foreach ($rows as $row) { $query = $this->connection->getQueryBuilder(); $query->insert('memories_places') @@ -79,5 +80,7 @@ trait TimelineWritePlaces ; $query->executeStatement(); } + + $this->connection->commit(); } }