Commit c9e818a1 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

erp5_api_style: WIP Introduce latests indexation timestamp object of the hash

parent b30a934a
......@@ -28,6 +28,7 @@
##############################################################################
from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from MySQLdb import ProgrammingError
from Products.ERP5Type import Permissions
......@@ -55,10 +56,10 @@ class JIOAPIRevisionMixin:
result = self.Base_zGetFromIOAPIRevisionTable(uid=self.getUid())
except ProgrammingError:
# jio_api_revision table is not created
return None, None
return None, None, None
if result:
return result[0].revision, result[0].hash
return None, None
return result[0].revision, result[0].hash, result[0].indexation_timestamp
return None, None, None
def _calculateHash(self):
hash_method = self.getTypeBasedMethod("calculatejIOAPIRevisionHash")
......@@ -71,27 +72,33 @@ class JIOAPIRevisionMixin:
"""
Update jIO API Revision
"""
indexation_timestamp = int(DateTime(self.getPortalObject().portal_catalog(
uid=self.getUid(), select_list=('indexation_timestamp',)
)[0].indexation_timestamp))
calculated_hash = self._calculateHash()
if not calculated_hash:
self._unindexJIOAPIRevision()
return
stored_hash = None
_, stored_hash = self._getJIOAPIRevisionTuple()
_, stored_hash, stored_timestamp = self._getJIOAPIRevisionTuple()
stored_timestamp = int(DateTime(stored_timestamp))
if stored_hash == calculated_hash:
if stored_timestamp != indexation_timestamp:
self.Base_zUpdateTimeStampjIOAPIRevisionTable(
uid=self.getUid(),
indexation_timestamp=indexation_timestamp,
)
return
new_revision = self.Base_getNewjIOAPIRevision()
try:
self.Base_zUpdatejIOAPIRevisionTable(
uid=self.getUid(),
revision=new_revision,
hash=calculated_hash,
)
except ProgrammingError:
# jio_api_revision table is not created
pass
self.Base_zUpdatejIOAPIRevisionTable(
uid=self.getUid(),
revision=new_revision,
hash=calculated_hash,
indexation_timestamp=indexation_timestamp,
)
return
security.declareProtected(Permissions.AccessContentsInformation,
......@@ -102,7 +109,7 @@ class JIOAPIRevisionMixin:
Fixing is not offered as it needs to be centralised to avoid missing a new revision for an object
"""
calculated_hash = self._calculateHash()
_, stored_hash = self._getJIOAPIRevisionTuple()
_, stored_hash, _ = self._getJIOAPIRevisionTuple()
if calculated_hash != stored_hash:
return [self.Base_translateString(
"Stored Hash ${stored_hash} difer from calculated hash ${calculated_hash}",
......
......@@ -22,4 +22,9 @@ object_list = portal.portal_catalog(**kw)
for element in object_list:
element.getObject().updateJIOAPIRevision()
# Catch any objects that might have fell through the cracks
object_list = context.Base_zSelectOutdatedjIOAPIRevisionTable()
for element in object_list:
portal.unrestrictedTraverse(element.relative_url).updateJIOAPIRevision()
context.activate(after_tag=tag).getId()
......@@ -2,5 +2,6 @@ CREATE TABLE `jio_api_revision` (
`uid` BIGINT UNSIGNED NOT NULL,
`revision` varchar(255) NOT NULL UNIQUE,
`hash` varchar(255),
`indexation_timestamp` TIMESTAMP(6),
PRIMARY KEY (`uid`)
) ENGINE=InnoDB
\ No newline at end of file
SELECT
revision, hash
revision, hash, indexation_timestamp
FROM
jio_api_revision
WHERE
......
select catalog.uid, catalog.relative_url from catalog join jio_api_revision on CAST(catalog.indexation_timestamp AS INT) != CAST(jio_api_revision.indexation_timestamp AS INT) AND catalog.uid = jio_api_revision.uid
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_col</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>name</string> </key>
<value> <string>uid</string> </value>
</item>
<item>
<key> <string>null</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>l</string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>name</string> </key>
<value> <string>relative_url</string> </value>
</item>
<item>
<key> <string>null</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>t</string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</list>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zSelectOutdatedjIOAPIRevisionTable</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
UPDATE
jio_api_revision
SET
indexation_timestamp=<dtml-sqlvar indexation_timestamp type=datetime>
WHERE
<dtml-sqltest uid op=eq type=int>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_col</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>uid\n
indexation_timestamp</string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>cmf_activity_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zUpdateTimeStampjIOAPIRevisionTable</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -13,6 +13,7 @@ VALUES
(
<dtml-sqlvar expr="uid" type="int">,
<dtml-sqlvar expr="revision" type="string" optional>,
<dtml-sqlvar expr="hash" type="string" optional>
<dtml-sqlvar expr="hash" type="string" optional>,
<dtml-sqlvar expr="indexation_timestamp" type="datetime" optional>
)
......@@ -10,7 +10,8 @@
<key> <string>arguments_src</string> </key>
<value> <string>uid\n
revision\n
hash</string> </value>
hash\n
indexation_timestamp</string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
......
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