Skip to content

Commit 92647bd

Browse files
authored
Removed keep in cache by default false in YdbQuery
Remove keep in cache by default false in YdbQuery
2 parents 2673cc8 + e6335ed commit 92647bd

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* fix keepInCache param in YdbQuery
12
* added Yson type
23
* add logger as Ydb config
34
* added snapshot mode in noninteractive transaction

src/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public function query($yql, array $parameters = null, array $options = [])
363363
$query = $this->newQuery($yql)
364364
->parameters($parameters)
365365
->txControl($tx_control)
366-
->keepInCache($this->keep_query_in_cache ?? ($parameters&&count($parameters)>0));
366+
->keepInCache($this->keep_query_in_cache);
367367

368368
if(isset($options['collectStats'])){
369369
$query->collectStats($options['collectStats']);

src/YdbQuery.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class YdbQuery
2727
/**
2828
* @var bool
2929
*/
30-
protected $keep_query_in_cache = false;
30+
protected $keep_query_in_cache = null;
3131

3232
/**
3333
* @var int
@@ -219,6 +219,17 @@ public function getRequestData()
219219
*/
220220
public function execute()
221221
{
222+
$this->keep_query_in_cache = self::isNeedSetKeepQueryInCache($this->keep_query_in_cache, $this->parameters);
222223
return $this->session->executeQuery($this);
223224
}
225+
226+
/**
227+
* @param bool|null $userFlag
228+
* @param array|null $queryDeclaredParams
229+
* @return bool
230+
*/
231+
protected static function isNeedSetKeepQueryInCache(?bool $userFlag, ?array $queryDeclaredParams): bool
232+
{
233+
return $userFlag ?? $queryDeclaredParams&&count($queryDeclaredParams)>0;
234+
}
224235
}

tests/KeepInCacheTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Test;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use YdbPlatform\Ydb\Session;
7+
8+
class KeepInCacheTest extends TestCase
9+
{
10+
protected $sampleParams = ["x", 1];
11+
12+
public function testIsNeedSetKeepQueryInCache()
13+
{
14+
$tests = [
15+
["flag" => null, "params" => null, "result" => false],
16+
["flag" => null, "params" => [], "result" => false],
17+
["flag" => null, "params" => $this->sampleParams, "result" => true],
18+
["flag" => false, "params" => null, "result" => false],
19+
["flag" => false, "params" => [], "result" => false],
20+
["flag" => false, "params" => $this->sampleParams, "result" => false],
21+
["flag" => true, "params" => null, "result" => true],
22+
["flag" => true, "params" => [], "result" => true],
23+
["flag" => true, "params" => $this->sampleParams, "result" => true],
24+
];
25+
foreach ($tests as $i => $test){
26+
self::assertEquals($test["result"], YdbQuery::isNeedSetKeepQueryInCache($test["flag"], $test["params"]));
27+
}
28+
}
29+
}
30+
class YdbQuery extends \YdbPlatform\Ydb\YdbQuery{
31+
public static function isNeedSetKeepQueryInCache(?bool $userFlag, ?array $queryDeclaredParams): bool
32+
{
33+
return parent::isNeedSetKeepQueryInCache($userFlag, $queryDeclaredParams);
34+
}
35+
}

0 commit comments

Comments
 (0)