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

Test the limitNum key when appending the limit #286

Closed
wants to merge 2 commits into from

Conversation

coudenysj
Copy link
Contributor

In the current implementation, it is possible that invalid queries are displayed in the profiler:

use myDb;
db.User.find({ "$and": [ { "_id": ObjectId("54ef2e9780c7e11e188b49ab") }, { "deletedAt": null } ] }).limit(1).limit();
db.Group.find({ "_id": { "$in": [ ObjectId("54ef2e9b80c7e11e188b4c5d") ] } }).sort([ ]);
db.Town.find({ "_id": ObjectId("54ef2e9280c7e11e188b4589") }).limit(1).limit();

With the suggested change, this results in:

use myDb;
db.User.find({ "$and": [ { "_id": ObjectId("54ef2e9780c7e11e188b49ab") }, { "deletedAt": null } ] }).limit(1);
db.Group.find({ "_id": { "$in": [ ObjectId("54ef2e9b80c7e11e188b4c5d") ] } }).sort([ ]);
db.Town.find({ "_id": ObjectId("54ef2e9280c7e11e188b4589") }).limit(1);

In the current implementation, it is possible that invalid queries are displayed in the profiler:

```php
use myDb;
db.User.find({ "$and": [ { "_id": ObjectId("54ef2e9780c7e11e188b49ab") }, { "deletedAt": null } ] }).limit(1).limit();
db.Group.find({ "_id": { "$in": [ ObjectId("54ef2e9b80c7e11e188b4c5d") ] } }).sort([ ]);
db.Town.find({ "_id": ObjectId("54ef2e9280c7e11e188b4589") }).limit(1).limit();
```

With the suggested change, this result in:

```php
use myDb;
db.User.find({ "$and": [ { "_id": ObjectId("54ef2e9780c7e11e188b49ab") }, { "deletedAt": null } ] }).limit(1);
db.Group.find({ "_id": { "$in": [ ObjectId("54ef2e9b80c7e11e188b4c5d") ] } }).sort([ ]);
db.Town.find({ "_id": ObjectId("54ef2e9280c7e11e188b4589") }).limit(1);
```
@stefantalen
Copy link

👍 Noticed the same, quite annoying to be misled by the Profiler

@malarzm
Copy link
Member

malarzm commented Mar 12, 2015

@coudenysj could you maybe add a test for this?

@coudenysj
Copy link
Contributor Author

I've added a unit test with data from my project, but I see the problem is not in the collect method, but in the logQuery. Some parts are logged twice.

@coudenysj
Copy link
Contributor Author

@malarzm Is this normal behaviour?

For one specific query, I get the following data:

Doctrine\Bundle\MongoDBBundle\DataCollector\StandardDataCollector::logQuery()
{
    echo print_r($query, true);
    echo debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
    $this->queries[] = $query;
}
Array
(
    [find] => 1
    [query] => Array
        (
            [_id] => MongoId Object
                (
                    [$id] => 5509a04b80c7e13d288b4c44
                )

        )

    [fields] => Array
        (
        )

    [db] => myproject
    [collection] => User
)
#0  Doctrine\Bundle\MongoDBBundle\DataCollector\StandardDataCollector->logQuery() called at [/vagrant/vendor/doctrine/mongodb-odm-bundle/Logger/AggregateLogger.php:39]
#1  Doctrine\Bundle\MongoDBBundle\Logger\AggregateLogger->logQuery()
#2  call_user_func_array() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCollection.php:68]
#3  Doctrine\MongoDB\LoggableCollection->log() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCollection.php:157]
#4  Doctrine\MongoDB\LoggableCollection->find() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:462]
#5  Doctrine\ODM\MongoDB\Persisters\DocumentPersister->load() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Proxy/ProxyFactory.php:175]
#6  Doctrine\ODM\MongoDB\Proxy\ProxyFactory->Doctrine\ODM\MongoDB\Proxy\{closure}()
#7  Closure->__invoke() called at [/vagrant/var/cache/dev/doctrine/odm/mongodb/Proxies/__CG__MyProjectDocumentUser.php:913]
#8  MongoDBODMProxies\__CG__\MyProject\Document\User->getVacations() called at [/vagrant/src/Controller/UserController.php:113]
#9  MyProject\Controller\UserController->detailAction()
#10 call_user_func_array() called at [/vagrant/var/bootstrap.php.cache:3022]
#11 Symfony\Component\HttpKernel\HttpKernel->handleRaw() called at [/vagrant/var/bootstrap.php.cache:2984]
#12 Symfony\Component\HttpKernel\HttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:3133]
#13 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:2377]
#14 Symfony\Component\HttpKernel\Kernel->handle() called at [/vagrant/app/app.php:36]

Array
(
    [limit] => 1
    [limitNum] => 1
    [query] => Array
        (
            [_id] => MongoId Object
                (
                    [$id] => 5509a04b80c7e13d288b4c44
                )

        )

    [fields] => Array
        (
        )

)
#0  Doctrine\Bundle\MongoDBBundle\DataCollector\StandardDataCollector->logQuery() called at [/vagrant/vendor/doctrine/mongodb-odm-bundle/Logger/AggregateLogger.php:39]
#1  Doctrine\Bundle\MongoDBBundle\Logger\AggregateLogger->logQuery()
#2  call_user_func() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCursor.php:66]
#3  Doctrine\MongoDB\LoggableCursor->log() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCursor.php:100]
#4  Doctrine\MongoDB\LoggableCursor->limit() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php:311]
#5  Doctrine\MongoDB\Cursor->getSingleResult() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:468]
#6  Doctrine\ODM\MongoDB\Persisters\DocumentPersister->load() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Proxy/ProxyFactory.php:175]
#7  Doctrine\ODM\MongoDB\Proxy\ProxyFactory->Doctrine\ODM\MongoDB\Proxy\{closure}()
#8  Closure->__invoke() called at [/vagrant/var/cache/dev/doctrine/odm/mongodb/Proxies/__CG__MyProjectDocumentUser.php:913]
#9  MongoDBODMProxies\__CG__\MyProject\Document\User->getVacations() called at [/vagrant/src/Controller/UserController.php:113]
#10 MyProject\Controller\UserController->detailAction()
#11 call_user_func_array() called at [/vagrant/var/bootstrap.php.cache:3022]
#12 Symfony\Component\HttpKernel\HttpKernel->handleRaw() called at [/vagrant/var/bootstrap.php.cache:2984]
#13 Symfony\Component\HttpKernel\HttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:3133]
#14 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:2377]
#15 Symfony\Component\HttpKernel\Kernel->handle() called at [/vagrant/app/app.php:36]

Array
(
    [limit] => 1
    [limitNum] => 
    [query] => Array
        (
            [_id] => MongoId Object
                (
                    [$id] => 5509a04b80c7e13d288b4c44
                )

        )

    [fields] => Array
        (
        )

)
#0  Doctrine\Bundle\MongoDBBundle\DataCollector\StandardDataCollector->logQuery() called at [/vagrant/vendor/doctrine/mongodb-odm-bundle/Logger/AggregateLogger.php:39]
#1  Doctrine\Bundle\MongoDBBundle\Logger\AggregateLogger->logQuery()
#2  call_user_func() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCursor.php:66]
#3  Doctrine\MongoDB\LoggableCursor->log() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/LoggableCursor.php:100]
#4  Doctrine\MongoDB\LoggableCursor->limit() called at [/vagrant/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php:314]
#5  Doctrine\MongoDB\Cursor->getSingleResult() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:468]
#6  Doctrine\ODM\MongoDB\Persisters\DocumentPersister->load() called at [/vagrant/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Proxy/ProxyFactory.php:175]
#7  Doctrine\ODM\MongoDB\Proxy\ProxyFactory->Doctrine\ODM\MongoDB\Proxy\{closure}()
#8  Closure->__invoke() called at [/vagrant/var/cache/dev/doctrine/odm/mongodb/Proxies/__CG__MyProjectDocumentUser.php:913]
#9  MongoDBODMProxies\__CG__\MyProject\Document\User->getVacations() called at [/vagrant/src/Controller/UserController.php:113]
#10 MyProject\Controller\UserController->detailAction()
#11 call_user_func_array() called at [/vagrant/var/bootstrap.php.cache:3022]
#12 Symfony\Component\HttpKernel\HttpKernel->handleRaw() called at [/vagrant/var/bootstrap.php.cache:2984]
#13 Symfony\Component\HttpKernel\HttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:3133]
#14 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle() called at [/vagrant/var/bootstrap.php.cache:2377]
#15 Symfony\Component\HttpKernel\Kernel->handle() called at [/vagrant/app/app.php:36]

@malarzm
Copy link
Member

malarzm commented Mar 19, 2015

@coudenysj what's concerning you?

@coudenysj
Copy link
Contributor Author

@malarzm It is not concerning me :).

I was just wondering if this query logging is correct.

If so, my unit test is correct an this pull request is complete :).

@coudenysj
Copy link
Contributor Author

@malarzm Does this PR needs any changes?

@malarzm malarzm added the bug label Jun 25, 2015
@malarzm malarzm added this to the 3.0.0 milestone Jun 25, 2015
@malarzm
Copy link
Member

malarzm commented Jun 25, 2015

@coudenysj I'm sorry, I was totally into ODM lately. As far as I'm concerned PR looks good but please let me revisit this and other PRs here soon. I've set milestone to not forget about it :)

@alcaeus alcaeus modified the milestones: 3.0.2, 3.0.0 Dec 1, 2015
@alcaeus
Copy link
Member

alcaeus commented Dec 20, 2015

Merged manually into 3.0 branch in 3a7419f. Thanks!

@alcaeus alcaeus closed this Dec 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants