New in DoctrineBundle 1.11.0

DoctrineBundle is the library that integrates the Doctrine DBAL and ORM libraries into Symfony applications. DoctrineBundle 1.11.0 has just been released and includes several new features and improvements. These are the most important ones.

Symfony Cache Pool Support

Using Symfony Cache pools for caching Doctrine's queries, metadata and results is now easier thanks to the new pool option. This allows using a Symfony Cache pool directly without having to create extra services:

  • YAML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    # config/packages/doctrine.yaml
    doctrine:
        orm:
            auto_generate_proxy_classes: false
            metadata_cache_driver:
                type: pool
                pool: doctrine.system_cache_pool
            query_cache_driver:
                type: pool
                pool: doctrine.system_cache_pool
            result_cache_driver:
                type: pool
                pool: doctrine.result_cache_pool
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <!-- config/packages/doctrine.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
        xsi:schemaLocation="http://symfony.com/schema/dic/services
            http://symfony.com/schema/dic/services/services-1.0.xsd
            http://symfony.com/schema/dic/doctrine
            http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
    
        <doctrine:config>
            <doctrine:orm>
                <doctrine:entity-manager>
                    <doctrine:query-cache-driver
                        type="pool"
                        pool="doctrine.system_cache_pool"
                    />
    
                    <doctrine:metadata-cache-driver
                        type="pool"
                        pool="doctrine.system_cache_pool"
                    />
    
                    <doctrine:result-cache-driver
                        type="pool"
                        pool="doctrine.result_cache_pool"
                    />
                </doctrine:entity-manager>
            </doctrine:orm>
        </doctrine:config>
    </container>
    

Using the new pool setting is optional, as is the dependency on symfony/cache. However, in the future, declaring caches through DoctrineCacheBundle will be deprecated, leaving only the id and pool cache types. Support for DoctrineCacheBundle will be dropped in DoctrineBundle 2.0.

Store Backtraces When Profiling Queries

The new profiling_collect_backtrace configuration option enables backtrace collection when logging a query. This helps you find the exact source of failing or problematic queries:

DoctrineBundle Query Backtrace

Because of the large amount of data this can produce, this option is disabled by default and you will need to enable it explicitly.

New Messenger Middleware Services

If you are using the Messenger component, there are new middleware services you can use to avoid connection issues to your database:

  • The doctrine_ping_connection middleware will attempt to ping the connection and will reconnect to the database if this ping wasn't successful. It will also reset the entity manager should it have been closed in the meantime.
  • The doctrine_close_connection middleware will close the connection after handling a message.

Comments

The `profiling_collect_backtrace` feature looks really great, it will immensely help debugging. Thank you for the contributions!
Simplification with integration of the Cache component seems awesome!
Oh, I like that !
Hm.. So I removed the two services defined by the DoctrineBundle recipe (https://github.com/symfony/recipes/blob/master/doctrine/doctrine-bundle/1.6/config/packages/prod/doctrine.yaml), doctrine.result_cache_provider, and doctrine.system_cache_provider and replaced the cache configuration witht he one shown above (as the recipe hasn't been updated) but now I get:

The service "doctrine.orm.default_entity_manager" has a dependency on a non
-existent service "doctrine.orm.cache.pool.doctrine.system_cache_pool".

Should I make this a ticket in the DoctrineBundle? As this new configuration above isn't mentioned there right now, I'm not sure if that would be the correct thing to do.
profiling_collect_backtrace ... Can we log backtrace when the query is slower than X ms? Something like the MySQL's slow log option. Such an option could provide a useful middle ground for development servers with only a little overhead.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.