Merge pull request #216 from goteo/feat/add-alt-index-on-translations

feat: change type of ext_translations.foreign_key to INT
This commit is contained in:
2026-07-13 15:31:58 +02:00
committed by GitHub
8 changed files with 500 additions and 491 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
"embed/embed": "^4.4",
"gedmo/doctrine-extensions": "^3.22",
"goteo/benzina": "^0.5",
"jolicode/automapper": "9.2.1",
"jolicode/automapper": "^9.2.1",
"knpuniversity/oauth2-client-bundle": "^2.20",
"league/oauth2-google": "^4.2",
"league/oauth2-server-bundle": "^1.1",
Generated
+442 -475
View File
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260710133732 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change ext_transalations.foreign_key from VARCHAR to INT to optimize localization joins';
}
public function up(Schema $schema): void
{
$count = (int) $this->connection->fetchOne(
"SELECT COUNT(*) FROM ext_translations WHERE foreign_key NOT REGEXP '^[0-9]+$'"
);
$this->abortIf(
$count > 0,
'Non-numeric values found in ext_translations.foreign_key.'
);
$this->addSql('ALTER TABLE ext_translations MODIFY foreign_key INT NOT NULL');
$this->addSql('OPTIMIZE TABLE ext_translations');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE ext_translations MODIFY foreign_key VARCHAR(64) NOT NULL');
}
}
@@ -3,6 +3,7 @@
namespace App\ApiResource;
use ApiPlatform\Metadata as API;
use AutoMapper\Attribute\MapFrom;
trait LocalizedApiResourceTrait
{
@@ -12,5 +13,11 @@ trait LocalizedApiResourceTrait
* @var array<string>
*/
#[API\ApiProperty(writable: false)]
public array $locales;
#[MapFrom(property: 'locales')]
public array $locales = [];
public function setLocales(array $locales): void
{
$this->locales = $locales;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ class Territory
*/
#[Assert\Country(alpha3: false)]
#[ORM\Column(type: Types::STRING, nullable: true)]
public readonly string $country;
public readonly ?string $country;
/**
* ISO 3166-2 first level subdivision code.\
+10 -3
View File
@@ -13,6 +13,7 @@ class AutoMapper implements AutoMapperInterface
public const DEFAULT_CONTEXT = [
MapperContext::DEPTH => 1,
MapperContext::SKIP_NULL_VALUES => true,
MapperContext::SKIP_UNINITIALIZED_VALUES => true,
];
private AutoMapperInterface $innerMapper;
@@ -31,11 +32,17 @@ class AutoMapper implements AutoMapperInterface
public function map(array|object $source, string|array|object $target, array $context = []): array|object|null
{
$context = [
return $this->innerMapper->map($source, $target, [
...self::DEFAULT_CONTEXT,
...$context,
];
]);
}
return $this->innerMapper->map($source, $target, $context);
public function mapCollection(iterable $collection, string $target, array $context = []): array
{
return $this->innerMapper->mapCollection($collection, $target, [
...self::DEFAULT_CONTEXT,
...$context,
]);
}
}
@@ -26,11 +26,7 @@ class AccountingStateProvider implements ProviderInterface
{
if ($operation instanceof CollectionOperationInterface) {
$accountings = $this->collectionProvider->provide($operation, $uriVariables, $context);
$resources = [];
foreach ($accountings as $accounting) {
$resources[] = $this->autoMapper->map($accounting, AccountingApiResource::class);
}
$resources = $this->autoMapper->mapCollection($accountings, AccountingApiResource::class);
return new TraversablePaginator(
new \ArrayIterator($resources),
+1 -5
View File
@@ -27,11 +27,7 @@ class ApiResourceStateProvider implements ProviderInterface
if ($operation instanceof CollectionOperationInterface) {
$collection = $this->collectionProvider->provide($operation, $uriVariables, $context);
$resources = [];
foreach ($collection as $item) {
$resources[] = $this->autoMapper->map($item, $resourceClass);
}
$resources = $this->autoMapper->mapCollection($collection, $resourceClass);
return new TraversablePaginator(
new \ArrayIterator($resources),