Skip to content

Commit

Permalink
rename cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Sep 6, 2024
1 parent fc49c25 commit c17c751
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions onadata/apps/api/tests/viewsets/test_entity_list_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def test_num_entities_cached(self):
entity_list = EntityList.objects.get(name="trees")
entity_list.num_entities = 5
entity_list.save()
cache.set(f"el-num-entities-{entity_list.pk}", 7)
cache.set(f"elist-num-entities-{entity_list.pk}", 7)

request = self.factory.get("/", **self.extra)
response = self.view(request)
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def setUp(self):
def test_delete(self, mock_now):
"""Delete Entity works"""
self.entity_list.refresh_from_db()
self.assertEqual(cache.get(f"el-num-entities-{self.entity_list.pk}"), 1)
self.assertEqual(cache.get(f"elist-num-entities-{self.entity_list.pk}"), 1)
date = datetime(2024, 6, 11, 14, 9, 0, tzinfo=timezone.utc)
mock_now.return_value = date

Expand All @@ -1200,7 +1200,7 @@ def test_delete(self, mock_now):
self.assertEqual(response.status_code, 204)
self.assertEqual(self.entity.deleted_at, date)
self.assertEqual(self.entity.deleted_by, self.user)
self.assertEqual(cache.get(f"el-num-entities-{self.entity_list.pk}"), 0)
self.assertEqual(cache.get(f"elist-num-entities-{self.entity_list.pk}"), 0)
self.assertEqual(
self.entity_list.last_entity_update_time, self.entity.date_modified
)
Expand Down
14 changes: 7 additions & 7 deletions onadata/libs/tests/utils/test_logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def test_entity_created(self):
self.assertCountEqual(entity.json, expected_json)
self.assertEqual(entity.uuid, "dbee4c32-a922-451c-9df7-42f40bf78f48")

self.assertEqual(cache.get(f"el-num-entities-{entity_list.pk}"), 1)
self.assertEqual(cache.get(f"elist-num-entities-{entity_list.pk}"), 1)
self.assertEqual(entity_list.last_entity_update_time, entity.date_modified)
self.assertEqual(entity.history.count(), 1)

Expand Down Expand Up @@ -805,11 +805,11 @@ def setUp(self):
self.entity_list = EntityList.objects.create(
name="trees", project=self.project, num_entities=10
)
self.ids_key = "el-num-entities-ids"
self.ids_key = "elist-num-entities-ids"
self.lock_key = f"{self.ids_key}-lock"
self.counter_key_prefix = "el-num-entities-"
self.counter_key_prefix = "elist-num-entities-"
self.counter_key = f"{self.counter_key_prefix}{self.entity_list.pk}"
self.created_at_key = "el-num-entities-ids-created-at"
self.created_at_key = "elist-num-entities-ids-created-at"

def tearDown(self) -> None:
super().tearDown()
Expand Down Expand Up @@ -927,13 +927,13 @@ def test_failover(self, mock_report_exc):
"is not configured or has malfunctioned"
)
mock_report_exc.assert_called_once_with(subject, msg)
self.assertEqual(cache.get("el-failover-report"), "sent")
self.assertEqual(cache.get("elist-failover-report-sent"), "sent")

@override_settings(ELIST_COUNTER_COMMIT_FAILOVER_TIMEOUT=3)
@patch("onadata.libs.utils.logger_tools.report_exception")
def test_failover_report_cache_hit(self, mock_report_exc):
"""Report exception not sent if cache `el-failover-report` set"""
cache.set("el-failover-report", "sent")
"""Report exception not sent if cache `elist-failover-report-sent` set"""
cache.set("elist-failover-report-sent", "sent")
cache_created_at = timezone.now() - timedelta(minutes=10)
cache.set(self.counter_key, 3)
cache.set(self.created_at_key, cache_created_at)
Expand Down
6 changes: 3 additions & 3 deletions onadata/libs/utils/cache_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
LOCK_SUFFIX = "-lock"

# Entities
ELIST_NUM_ENTITIES = "el-num-entities-"
ELIST_NUM_ENTITIES_IDS = "el-num-entities-ids"
ELIST_NUM_ENTITIES = "elist-num-entities-"
ELIST_NUM_ENTITIES_IDS = "elist-num-entities-ids"
ELIST_NUM_ENTITIES_LOCK = f"{ELIST_NUM_ENTITIES_IDS}{LOCK_SUFFIX}"
ELIST_NUM_ENTITIES_CREATED_AT = f"{ELIST_NUM_ENTITIES_IDS}-created-at"

# Report exception
ELIST_FAILOVER_REPORT = "el-failover-report"
ELIST_FAILOVER_REPORT = "elist-failover-report-sent"


def safe_delete(key):
Expand Down

0 comments on commit c17c751

Please sign in to comment.