leancloud / php-sdk

LeanCloud PHP SDK
Apache License 2.0
53 stars 23 forks source link

Modify a condition when reuse the query #164

Closed actors315 closed 4 years ago

codecov-io commented 6 years ago

Codecov Report

Merging #164 into master will increase coverage by 0.66%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
+ Coverage   66.37%   67.04%   +0.66%     
==========================================
  Files          33       33              
  Lines        2427     2142     -285     
==========================================
- Hits         1611     1436     -175     
+ Misses        816      706     -110
Impacted Files Coverage Δ
src/LeanCloud/Query.php 94.37% <0%> (-2.39%) :arrow_down:
src/LeanCloud/CloudException.php 50% <0%> (-10%) :arrow_down:
src/LeanCloud/ACL.php 79.2% <0%> (-2.21%) :arrow_down:
src/LeanCloud/Engine/Cloud.php 88.52% <0%> (-1.62%) :arrow_down:
src/LeanCloud/Push.php 85.36% <0%> (-1.6%) :arrow_down:
src/LeanCloud/SaveOption.php 90.9% <0%> (-1.4%) :arrow_down:
src/LeanCloud/File.php 82.99% <0%> (-1.04%) :arrow_down:
src/LeanCloud/Operation/RelationOperation.php 84.72% <0%> (-0.82%) :arrow_down:
src/LeanCloud/GeoPoint.php 88.23% <0%> (-0.66%) :arrow_down:
src/LeanCloud/Object.php 89.66% <0%> (-0.51%) :arrow_down:
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update de96d95...92ac92c. Read the comment docs.

juvenn commented 6 years ago

谢谢贡献。这里有一个问题,为什么不通过新建 query 的方式呢?新建 query 的成本并不高。query 复用,可能会导致非预期的查询。能举个具体的代码例子吗?

actors315 commented 6 years ago

新建query确实可以避免复用的问题。我需要复用query的情况是多条件查询时,其他条件都一致,只是其中某一个条件不同。比如

"query": { "promotions": "YES", "timeZone": { "$regex": "^Africa/" }, ....省略其他条件 },

"query": { "promotions": "YES", "timeZone": "America/Puerto_Rico", // 因为条件规则不一致,上一条件需要正则,这里相等匹配,无法直接覆盖上一条件,所以需要先reset掉上一条件 ....省略其他条件 },

foreach ($areas as $v) {
    $query->resetCondition('timeZone');
    if ($this->area_config[$v]['type'] == 2) {
        $query->equalTo('timeZone', $this->area_config[$v]['code']);
    } else {
        $query->startsWith('timeZone', $this->area_config[$v]['code']);
    }
}
weakish commented 4 years ago

有很多类似查询的场景下也可以写函数构造多个 query,复用 query 的优势不明显,这里先关掉了。