Skip to content

Commit c201760

Browse files
authored
Merge pull request #2635 from shlinkio/develop
Release 5.1.5
2 parents eb234c1 + 59c62a2 commit c201760

2 files changed

Lines changed: 46 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
66

7+
## [5.1.5] - 2026-06-22
8+
### Added
9+
* *Nothing*
10+
11+
### Changed
12+
* *Nothing*
13+
14+
### Deprecated
15+
* *Nothing*
16+
17+
### Removed
18+
* *Nothing*
19+
20+
### Fixed
21+
* [#2634](https://github.com/shlinkio/shlink/issues/2634) Improve performance of Version20260607082210 migration by fetching short URLs in batches.
22+
23+
724
## [5.1.4] - 2026-06-18
825
### Added
926
* *Nothing*

module/Core/migrations/Version20260607082210.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
final class Version20260607082210 extends AbstractMigration
1818
{
1919
public function up(Schema $schema): void
20+
{
21+
do {
22+
$resultsFound = $this->processBatch();
23+
} while ($resultsFound);
24+
}
25+
26+
public function processBatch(): bool
2027
{
2128
$qb = $this->connection->createQueryBuilder();
2229
$qb
@@ -25,37 +32,33 @@ public function up(Schema $schema): void
2532
// If this migration times out, this will ensure it can be rerun, and it will continue where it was left, so
2633
// it can be run multiple times until all short URLs have been processed
2734
->where($qb->expr()->eq('long_url_hash', ':longUrlHash'))
28-
->setParameters(['longUrlHash' => '']);
35+
->setParameters(['longUrlHash' => ''])
36+
->setMaxResults(10_000);
2937
$shortUrlsResult = $qb->executeQuery();
3038

31-
$iteration = 1;
32-
$this->connection->beginTransaction();
39+
return $this->connection->transactional(function () use ($shortUrlsResult) {
40+
$resultsFound = false;
3341

34-
while ($row = $shortUrlsResult->fetchAssociative()) {
35-
// Every few updates, commit the transaction and begin a new one
36-
if (($iteration % 10_000) === 0) {
37-
$this->connection->commit();
38-
$this->connection->beginTransaction();
39-
}
40-
$iteration++;
42+
while ($row = $shortUrlsResult->fetchAssociative()) {
43+
$resultsFound = true;
4144

42-
$updateQb = $this->connection->createQueryBuilder();
43-
$updateQb
44-
->update('short_urls')
45-
->set('long_url_hash', ':binHash')
46-
->where($updateQb->expr()->eq('id', ':id'))
47-
->setParameters([
48-
'id' => $row['id'],
49-
'binHash' => hex2bin(hash('sha256', $row['original_url'])),
50-
], [
51-
'binHash' => Types::BINARY,
52-
])
53-
->setMaxResults(1)
54-
->executeStatement();
55-
}
45+
$updateQb = $this->connection->createQueryBuilder();
46+
$updateQb
47+
->update('short_urls')
48+
->set('long_url_hash', ':binHash')
49+
->where($updateQb->expr()->eq('id', ':id'))
50+
->setParameters([
51+
'id' => $row['id'],
52+
'binHash' => hex2bin(hash('sha256', $row['original_url'])),
53+
], [
54+
'binHash' => Types::BINARY,
55+
])
56+
->setMaxResults(1)
57+
->executeStatement();
58+
}
5659

57-
// Commit any pending update that is still pending
58-
$this->connection->commit();
60+
return $resultsFound;
61+
});
5962
}
6063

6164
public function isTransactional(): bool

0 commit comments

Comments
 (0)