Skip to content

Commit

Permalink
fix(Water Body): use shared cache
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Apr 22, 2024
1 parent 03e333c commit ad995e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions landa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def water_body(id: str = None, fishing_area: str = None, only_id: int = 0) -> Li
return build_water_body_data(id, fishing_area)

key = fishing_area or "all"
cache_exists = frappe.cache().hexists("water_body_data", key)
cache_exists = frappe.cache().hexists("water_body_data", key, shared=True)

if not cache_exists:
# Build the cache (for future calls)
Expand All @@ -96,7 +96,7 @@ def water_body(id: str = None, fishing_area: str = None, only_id: int = 0) -> Li

def get_water_body_cache(key: str) -> List[Dict]:
"""Return a **CACHED** list of water bodies with fish species and special provisions."""
return frappe.cache().hget("water_body_data", key)
return frappe.cache().hget("water_body_data", key, shared=True)


@frappe.whitelist(allow_guest=True, methods=["GET"])
Expand Down
12 changes: 6 additions & 6 deletions landa/water_body_management/doctype/water_body/water_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ def rebuild_water_body_cache(fishing_area: str = None, enqueued: bool = False):
"""
# Invalidate Cache
if enqueued:
frappe.cache().hset("water_body_data", "in_progress", 1)
frappe.cache().hset("water_body_data", "in_progress", 1, shared=True)

frappe.cache().hdel("water_body_data", "all")
frappe.cache().hdel("water_body_data", "all", shared=True)
build_water_body_cache()

if fishing_area:
frappe.cache().hdel("water_body_data", fishing_area)
frappe.cache().hdel("water_body_data", fishing_area, shared=True)
build_water_body_cache(fishing_area=fishing_area)

if enqueued:
frappe.cache().hset("water_body_data", "in_progress", 0)
frappe.cache().hset("water_body_data", "in_progress", 0, shared=True)


def remove_outdated_information():
Expand All @@ -93,7 +93,7 @@ def build_water_body_cache(fishing_area: str = None):
"""
water_bodies = build_water_body_data(fishing_area=fishing_area)
key = fishing_area or "all"
frappe.cache().hset("water_body_data", key, water_bodies)
frappe.cache().hset("water_body_data", key, water_bodies, shared=True)


def build_water_body_data(id: str = None, fishing_area: str = None) -> List[Dict]:
Expand Down Expand Up @@ -277,7 +277,7 @@ def rebuild_cache_on_attachment(doc, method):
# NOTE:Enqueue gets uncommitted data (new thread). Files appear even if deleted
# Still no clue why
rebuild_water_body_cache(fishing_area=water_body_data.fishing_area)
elif not frappe.cache().hget("water_body_data", "in_progress"):
elif not frappe.cache().hget("water_body_data", "in_progress", shared=True):
frappe.enqueue(
rebuild_water_body_cache,
fishing_area=water_body_data.fishing_area,
Expand Down

0 comments on commit ad995e1

Please sign in to comment.