Openbravo Issue Tracking System - Retail Modules
View Issue Details
0036954Retail ModulesWeb POSpublic2017-09-26 13:482017-10-26 16:38
marvintm 
gorka_gil 
normalmajorhave not tried
closedfixed 
5
 
RR18Q1 
marvintm
No
0036954: buildIdentifier function in ob-cache doesn't take into account property names in the criteria
The buildIdentifier function in ob-cache, which is used by the caching mechanism which is used by OB.Dal.findUsingCache and OB.Dal.queryUsingCache, doesn't take into account property names, only their values, when serializing a criteria.

This means that if somebody tries to use the same cache for two different queries which query the same table but have different criterias, it could happen that incorrect results are returned.

Although this was not considered the proper usage of the API in the original implementation, taking property names into account would make the API friendlier to use, and would protect it against developer mistakes.
Login in the Web POS. Then, execute the following two queries:

OB.Dal.find(OB.Model.Product, {isGeneric: true}, function(data){console.log(data);})

OB.Dal.find(OB.Model.Product, {bestseller: true}, function(data){console.log(data);})


Verify that they return two different sets of products (makes sense, because the criteria is different).

Now try the following two:

OB.Dal.findUsingCache("productCache", OB.Model.Product, {isGeneric: true}, function(data){console.log(data);})
OB.Dal.findUsingCache("productCache", OB.Model.Product, {bestseller: true}, function(data){console.log(data);})

Both queries are using the same cache (which is something arguably does not make sense), but in any case, they return the same result, which is most likely wrong according to what the developer expected.

If we included the whole criteria in the buildIdentifier function, this would not happen, as two different sets of results would have been created in the cache.
Change the buildIdentifier function so that it serializes the whole criteria to JSON. This way, we would not be losing the property names, and this problem would not happen.
No tags attached.
Issue History
2017-09-26 13:48marvintmNew Issue
2017-09-26 13:48marvintmAssigned To => Retail
2017-09-26 13:48marvintmTriggers an Emergency Pack => No
2017-09-26 13:50marvintmSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=15993#r15993
2017-10-02 16:22gorka_gilAssigned ToRetail => gorka_gil
2017-10-09 18:15gorka_gilStatusnew => scheduled
2017-10-13 09:23hgbotCheckin
2017-10-13 09:23hgbotNote Added: 0099882
2017-10-13 09:24hgbotCheckin
2017-10-13 09:24hgbotNote Added: 0099883
2017-10-13 09:24hgbotStatusscheduled => resolved
2017-10-13 09:24hgbotResolutionopen => fixed
2017-10-13 09:24hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/540216bb64224392b0a4004b80526da5b08579dd [^]
2017-10-26 16:38marvintmReview Assigned To => marvintm
2017-10-26 16:38marvintmStatusresolved => closed
2017-10-26 16:38marvintmFixed in Version => RR18Q1

Notes
(0099882)
hgbot   
2017-10-13 09:23   
Repository: tools/automation/pi-mobile
Changeset: 173c5786f32f3be40d9b0f0ed1ab489ba6abc167
Author: Gorka Gil <gorka.gil <at> openbravo.com>
Date: Fri Oct 13 09:07:10 2017 +0200
URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/173c5786f32f3be40d9b0f0ed1ab489ba6abc167 [^]

Related to issue 36954: buildIdentifier function in ob-cache doesn't take into account property names in the criteria

Added test to check that findUsingCache continues caching queries

---
A src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36954_FindUsingCache.java
---
(0099883)
hgbot   
2017-10-13 09:24   
Repository: erp/pmods/org.openbravo.mobile.core
Changeset: 540216bb64224392b0a4004b80526da5b08579dd
Author: Gorka Gil <gorka.gil <at> openbravo.com>
Date: Tue Oct 10 17:27:37 2017 +0200
URL: http://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/rev/540216bb64224392b0a4004b80526da5b08579dd [^]

Fixed issue 36954: buildIdentifier function in ob-cache doesn't take into account property names in the criteria

Put the serialized params as identifier for caching

Details:
 - Mantained the delete of obj.sql, since some times the params are duplicated.
 - Sometimes the params are "[]" and other "", to unify the empty params added an exception for empty case.
 - Unified the case for remote and local

---
M web/org.openbravo.mobile.core/source/data/ob-cache.js
---