Skip to content

Commit

Permalink
Don't reindex section when we receive no JSON (ex: timeout)
Browse files Browse the repository at this point in the history
This will reduce ZODB transactions numbers
This refs WEB-3995
  • Loading branch information
laulaz committed Sep 9, 2024
1 parent 3581b20 commit 931e22b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changelog
1.2.68 (unreleased)
-------------------

- WEB-3995 : Don't reindex section when we receive no JSON (ex: timeout)
This will reduce ZODB transactions numbers.
[bsuttor, laulaz, remdub]

- CITI-4 : Add conditional log to debug WCA token errors
[laulaz]

Expand Down
7 changes: 4 additions & 3 deletions src/imio/smartweb/core/contents/sections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ class HashableJsonSectionView(SectionView):
json_data = None

def refresh_modification_date(self):
new_hash = None
if self.json_data is not None:
new_hash = hash_md5(json.dumps(self.json_data))
if self.json_data is None:
# Don't reindex section when we receive no JSON (ex: timeout)
return
new_hash = hash_md5(json.dumps(self.json_data))
annotations = IAnnotations(self.context)
stored_hash = annotations.get(SECTION_ITEMS_HASH_KEY)
if stored_hash != new_hash:
Expand Down
9 changes: 9 additions & 0 deletions src/imio/smartweb/core/tests/test_section_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def test_news_modified(self, m):
self.assertEqual(hash_2, hash_3)
self.assertEqual(next_modification, last_modification)

sleep(1)
url = "http://localhost:8080/Plone/@search?selected_news_folders=64f4cbee9a394a018a951f6d94452914&portal_type=imio.news.NewsItem&metadata_fields=container_uid&metadata_fields=category_title&metadata_fields=local_category&metadata_fields=topics&metadata_fields=has_leadimage&metadata_fields=modified&metadata_fields=effective&metadata_fields=UID&sort_limit=6&translated_in_en=1&sort_on=effective&sort_order=descending"
m.get(url, text=None)
self.assertEqual(len(news_view.items), 0)
no_modification = self.portalpage.ModificationDate()
hash_4 = annotations.get(SECTION_ITEMS_HASH_KEY)
self.assertEqual(hash_3, hash_4)
self.assertEqual(last_modification, no_modification)

@requests_mock.Mocker()
def test_orientation(self, m):
intids = getUtility(IIntIds)
Expand Down
3 changes: 2 additions & 1 deletion src/imio/smartweb/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def get_json(url, auth=None, timeout=5):
return None
if response.status_code != 200:
return None
return json.loads(response.text)
if response.text:
return json.loads(response.text)


def get_wca_token(client_id, client_secret):
Expand Down

0 comments on commit 931e22b

Please sign in to comment.