Commit 3dd65f28 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 b56f29ad
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from MySQLdb import ProgrammingError from MySQLdb import ProgrammingError
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
...@@ -55,10 +56,10 @@ class JIOAPIRevisionMixin: ...@@ -55,10 +56,10 @@ class JIOAPIRevisionMixin:
result = self.Base_zGetFromIOAPIRevisionTable(uid=self.getUid()) result = self.Base_zGetFromIOAPIRevisionTable(uid=self.getUid())
except ProgrammingError: except ProgrammingError:
# jio_api_revision table is not created # jio_api_revision table is not created
return None, None return None, None, None
if result: if result:
return result[0].revision, result[0].hash return result[0].revision, result[0].hash, result[0].indexation_timestamp
return None, None return None, None, None
def _calculateHash(self): def _calculateHash(self):
hash_method = self.getTypeBasedMethod("calculatejIOAPIRevisionHash") hash_method = self.getTypeBasedMethod("calculatejIOAPIRevisionHash")
...@@ -71,27 +72,33 @@ class JIOAPIRevisionMixin: ...@@ -71,27 +72,33 @@ class JIOAPIRevisionMixin:
""" """
Update jIO API Revision 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() calculated_hash = self._calculateHash()
if not calculated_hash: if not calculated_hash:
self._unindexJIOAPIRevision() self._unindexJIOAPIRevision()
return return
stored_hash = None 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_hash == calculated_hash:
if stored_timestamp != indexation_timestamp:
self.Base_zUpdateTimeStampjIOAPIRevisionTable(
uid=self.getUid(),
indexation_timestamp=indexation_timestamp,
)
return return
new_revision = self.Base_getNewjIOAPIRevision() new_revision = self.Base_getNewjIOAPIRevision()
try: self.Base_zUpdatejIOAPIRevisionTable(
self.Base_zUpdatejIOAPIRevisionTable( uid=self.getUid(),
uid=self.getUid(), revision=new_revision,
revision=new_revision, hash=calculated_hash,
hash=calculated_hash, indexation_timestamp=indexation_timestamp,
) )
except ProgrammingError:
# jio_api_revision table is not created
pass
return return
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -102,7 +109,7 @@ class JIOAPIRevisionMixin: ...@@ -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 Fixing is not offered as it needs to be centralised to avoid missing a new revision for an object
""" """
calculated_hash = self._calculateHash() calculated_hash = self._calculateHash()
_, stored_hash = self._getJIOAPIRevisionTuple() _, stored_hash, _ = self._getJIOAPIRevisionTuple()
if calculated_hash != stored_hash: if calculated_hash != stored_hash:
return [self.Base_translateString( return [self.Base_translateString(
"Stored Hash ${stored_hash} difer from calculated hash ${calculated_hash}", "Stored Hash ${stored_hash} difer from calculated hash ${calculated_hash}",
......
...@@ -22,4 +22,9 @@ object_list = portal.portal_catalog(**kw) ...@@ -22,4 +22,9 @@ object_list = portal.portal_catalog(**kw)
for element in object_list: for element in object_list:
element.getObject().updateJIOAPIRevision() 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() context.activate(after_tag=tag).getId()
...@@ -2,5 +2,6 @@ CREATE TABLE `jio_api_revision` ( ...@@ -2,5 +2,6 @@ CREATE TABLE `jio_api_revision` (
`uid` BIGINT UNSIGNED NOT NULL, `uid` BIGINT UNSIGNED NOT NULL,
`revision` varchar(255) NOT NULL UNIQUE, `revision` varchar(255) NOT NULL UNIQUE,
`hash` varchar(255), `hash` varchar(255),
`indexation_timestamp` TIMESTAMP(6),
PRIMARY KEY (`uid`) PRIMARY KEY (`uid`)
) ENGINE=InnoDB ) ENGINE=InnoDB
\ No newline at end of file
SELECT SELECT
revision, hash revision, hash, indexation_timestamp
FROM FROM
jio_api_revision jio_api_revision
WHERE 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 ...@@ -13,6 +13,7 @@ VALUES
( (
<dtml-sqlvar expr="uid" type="int">, <dtml-sqlvar expr="uid" type="int">,
<dtml-sqlvar expr="revision" type="string" optional>, <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 @@ ...@@ -10,7 +10,8 @@
<key> <string>arguments_src</string> </key> <key> <string>arguments_src</string> </key>
<value> <string>uid\n <value> <string>uid\n
revision\n revision\n
hash</string> </value> hash\n
indexation_timestamp</string> </value>
</item> </item>
<item> <item>
<key> <string>connection_id</string> </key> <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