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

Doctrine performance improvements #224

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Composer install
run: composer install --prefer-dist --no-progress --no-suggest --no-dev --optimize-autoloader

- name: Generate proxies
run: php bin/doctrine orm:generate-proxies

- name: Deploy with rsync
uses: burnett01/[email protected]
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ env.php
# Logs
/logs
/tests/runtime

# Doctrine Proxies
/database/proxies
27 changes: 25 additions & 2 deletions engine/core/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,46 @@
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\ORM\Query\TokenType;

use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;

class DB extends SingletonDependency
{
private const PATH_PROXIES = "database/proxies";

private EntityManager $entityManager;

function __construct(Doctrine\DBAL\Connection $connection = null)
{
$evm = new \Doctrine\Common\EventManager;
$tablePrefix = new \TablePrefix('orm_');
$evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
$devMode = !!env("DEVELOPMENT");

if ($devMode) {
$queryCache = new ArrayAdapter();
$metadataCache = new ArrayAdapter();
} else {
$queryCache = new PhpFilesAdapter('doctrine_queries');
$metadataCache = new PhpFilesAdapter('doctrine_metadata');
}

$config = ORMSetup::createAttributeMetadataConfiguration(paths: array("database/models"), isDevMode: true);
$config = ORMSetup::createAttributeMetadataConfiguration(paths: array("database/models"), isDevMode: $devMode, proxyDir: self::PATH_PROXIES);
$config->setMetadataCache($metadataCache);
$config->setQueryCache($queryCache);
$config->addCustomDatetimeFunction('MONTH', Month::class);
$config->addCustomDatetimeFunction('DAY', Day::class);


if ($devMode) {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
Autoloader::register(self::PATH_PROXIES, "");
}

$connection ??= DriverManager::getConnection([
'driver' => 'pdo_mysql',
'user' => env("DB_USER"),
Expand Down
Loading