-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changing the position of the emptied variable #3997
Conversation
When use fetch or fetch fetchColumn they don't close the cursor and don't save in the cache
I do not understand. Can you please elaborate? |
When this query is made
It is not saved in the cache, because it has not been passed in all registers and the variable $emptied in lib/Doctrine/DBAL/Cache/ResultCacheStatement.php is never true when we call closeCursor. It will only be true if you pass all registers with while for example and then will save in the cache when we call closeCursor. But is not the case of this query, this query only need the first register. And otherwise it will not influence if someone needs to pass all the registers, it will save in the cache too. |
Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>
Pardon my ignorance but… what is a register? What are you referring to? |
Sorry, I mean, without this pull request you need to do like this for save the cache using the fetch method
You need get all rows. If you get just the first $row, they don't save the cache.
And I think don't matter if you get one row or all rows to save the cache, it necessary save in the cache always. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@greg0ire I haven't checked all tests in the repository, but is it possible that we don't have a test that checks the cache behaviour with parameters?
@@ -165,7 +165,7 @@ public function testDontFinishNoCache() : void | |||
|
|||
$this->hydrateStmt($stmt, FetchMode::NUMERIC); | |||
|
|||
self::assertCount(2, $this->sqlLogger->queries); | |||
self::assertCount(1, $this->sqlLogger->queries); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, isn't this test supposed to have 2 queries executed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, a second query he took from the cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was incorrect because, just will save the query in $this->sqlLogger->queries when the query are execute in the database.
dbal/lib/Doctrine/DBAL/Connection.php
Lines 894 to 897 in 4c03ed8
$logger = $this->_config->getSQLLogger(); | |
if ($logger) { | |
$logger->startQuery($query, $params, $types); | |
} |
When the query are in the cache, they return before
dbal/lib/Doctrine/DBAL/Connection.php
Lines 886 to 897 in 4c03ed8
public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) | |
{ | |
if ($qcp !== null) { | |
return $this->executeCacheQuery($query, $params, $types, $qcp); | |
} | |
$connection = $this->getWrappedConnection(); | |
$logger = $this->_config->getSQLLogger(); | |
if ($logger) { | |
$logger->startQuery($query, $params, $types); | |
} |
The reason are the cache doesn't work before, when we use fetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, which is why I approved if at first, but if there's another reason why @beberlei expected 2 in the past, I want to know and would like to be on the save side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was recently changed in #4048. It's an improvement, not a bugfix, so this change shouldn't be made in 2.10.x.
.
@SenseException what do you mean by "with parameters"? |
@greg0ire Every |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely resolved by #4048.
@@ -931,9 +931,10 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach | |||
* @param int[]|string[] $types The types the previous parameters are in. | |||
* @param QueryCacheProfile $qcp The query cache profile. | |||
* | |||
* @return ResultStatement | |||
* @return ResultCacheStatement|ArrayStatement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert. The type hint should refer to an interface, not to a specific implementation.
|
||
$iterator = $stmt->getIterator(); | ||
|
||
self::assertCount(1, $iterator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a valid behavior to expect. The fact that the iterator internally calls fetchAll()
is a bug (see #2718) and shouldn't be relied upon to expect that the statement is cached just because an iterator over its results was instantiated.
@dfrnks I believe so. You can check your case using the |
When use fetch or fetchColumn and don't pass for all registers if while they don't close the cursor and don't save in the cache
Summary