Commit ac62192a authored by Tatuya Kamada's avatar Tatuya Kamada

Revert "Invenotory: Change to use inventory cache even if we do not specify the date."

Needs more tests.

This reverts commit 74db4d39.
parent 74db4d39
...@@ -60,10 +60,8 @@ FROM \n ...@@ -60,10 +60,8 @@ FROM \n
inventory_cache \n inventory_cache \n
WHERE \n WHERE \n
inventory_cache.query=<dtml-sqlvar query type="string"> \n inventory_cache.query=<dtml-sqlvar query type="string"> \n
<dtml-if date>\n
AND \n AND \n
inventory_cache.date <= <dtml-sqlvar date type="datetime">\n inventory_cache.date <= <dtml-sqlvar date type="datetime"> \n
</dtml-if>\n
ORDER BY \n ORDER BY \n
date DESC date DESC
......
14 13
\ No newline at end of file \ No newline at end of file
...@@ -1303,6 +1303,7 @@ class SimulationTool(BaseTool): ...@@ -1303,6 +1303,7 @@ class SimulationTool(BaseTool):
# Get cached data # Get cached data
if getattr(self, "Resource_zGetInventoryCacheResult", None) is not None and \ if getattr(self, "Resource_zGetInventoryCacheResult", None) is not None and \
optimisation__ and (not kw.get('from_date')) and \ optimisation__ and (not kw.get('from_date')) and \
(bool(kw.get("at_date")) ^ bool(kw.get("to_date"))) and \
'transformed_resource' not in kw: 'transformed_resource' not in kw:
# Here is the different kind of date # Here is the different kind of date
# from_date : >= # from_date : >=
...@@ -1313,7 +1314,7 @@ class SimulationTool(BaseTool): ...@@ -1313,7 +1314,7 @@ class SimulationTool(BaseTool):
# of the same line # of the same line
at_date = kw.pop("at_date", None) at_date = kw.pop("at_date", None)
if at_date is None: if at_date is None:
to_date = kw.pop("to_date", None) to_date = kw.pop("to_date")
else: else:
# add one second so that we can use to_date # add one second so that we can use to_date
to_date = at_date + MYSQL_MIN_DATETIME_RESOLUTION to_date = at_date + MYSQL_MIN_DATETIME_RESOLUTION
...@@ -1401,9 +1402,10 @@ class SimulationTool(BaseTool): ...@@ -1401,9 +1402,10 @@ class SimulationTool(BaseTool):
**kw)).digest() **kw)).digest()
# Try to get result from cache # Try to get result from cache
Resource_zGetInventoryCacheResult = self.Resource_zGetInventoryCacheResult Resource_zGetInventoryCacheResult = self.Resource_zGetInventoryCacheResult
inventory_cache_kw = {'query': sql_text_hash} inventory_cache_kw = {
if to_date is not None: 'query': sql_text_hash,
inventory_cache_kw['date'] = to_date 'date': to_date,
}
try: try:
cached_sql_result = Resource_zGetInventoryCacheResult(**inventory_cache_kw) cached_sql_result = Resource_zGetInventoryCacheResult(**inventory_cache_kw)
except ProgrammingError: except ProgrammingError:
...@@ -1432,10 +1434,10 @@ class SimulationTool(BaseTool): ...@@ -1432,10 +1434,10 @@ class SimulationTool(BaseTool):
else: else:
cached_result = [] cached_result = []
cache_lag = self.getInventoryCacheLag() cache_lag = self.getInventoryCacheLag()
if cached_sql_result and (to_date is None or (to_date - DateTime(cached_sql_result[0].date) < cache_lag)): if cached_sql_result and to_date - DateTime(cached_sql_result[0].date) < cache_lag:
cached_date = DateTime(cached_sql_result[0].date) cached_date = DateTime(cached_sql_result[0].date)
result = cached_result result = cached_result
elif to_date is not None: else:
# Cache miss, or hit with old data: store a new entry in cache. # Cache miss, or hit with old data: store a new entry in cache.
# Don't store it at to_date, as it risks being flushed soon (ie, when # Don't store it at to_date, as it risks being flushed soon (ie, when
# any document older than to_date gets reindexed in stock table). # any document older than to_date gets reindexed in stock table).
...@@ -1473,12 +1475,6 @@ class SimulationTool(BaseTool): ...@@ -1473,12 +1475,6 @@ class SimulationTool(BaseTool):
'data': result._data, 'data': result._data,
}), }),
) )
else:
# Cache miss and this getInventory() not specifying to_date,
# and other getInventory() have not created usable caches.
# In such case, do not create cache, do not use cache.
result = []
cached_date = None
if src__: if src__:
result = sql_source_list result = sql_source_list
return result, cached_date return result, cached_date
......
...@@ -3022,45 +3022,6 @@ class TestInventoryCacheTable(InventoryAPITestCase): ...@@ -3022,45 +3022,6 @@ class TestInventoryCacheTable(InventoryAPITestCase):
} }
) )
def test_17_GetInventoryWithoutDate(self):
"""
Check getInventory without date. Without date means specifying
infinite future date. So it try to retrieve the latest cache.
Note: This behavior is compatible with the old caching implementation
that was using inventory_stock table. In other words, this brings backs
the backword compatibility in invetory caching.
"""
self.assertInventoryEquals(
self._fillCache(),
inventory_kw={
'node_uid': self.node_uid,
},
)
def test_18_GetInventoryWithoutDate(self):
"""
Check that getInventoryList without date retrives the latest caches.
"""
self._fillCache(True)
# Check we got all results
self._checkInventoryList(
self.getInventoryList(node_uid=self.node_uid),
[{
'date': self.INVENTORY_DATE_3,
'inventory': self.INVENTORY_QUANTITY_3,
'node_uid': self.node_uid,
}, {
'date': self.INVENTORY_DATE_2,
'inventory': self.INVENTORY_QUANTITY_2,
'node_uid': self.node_uid,
}, {
'date': self.INVENTORY_DATE_1,
'inventory': self.INVENTORY_QUANTITY_1,
'node_uid': self.node_uid,
}],
)
class BaseTestUnitConversion(InventoryAPITestCase): class BaseTestUnitConversion(InventoryAPITestCase):
QUANTITY_UNIT_DICT = {} QUANTITY_UNIT_DICT = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment