mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-23 21:25:12 +00:00
Fix cache multithreading issues on startup?
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import threading
|
||||
from datetime import timedelta
|
||||
|
||||
from requests_cache import CachedSession
|
||||
@@ -5,6 +6,19 @@ from requests_cache import CachedSession
|
||||
# Cache for "semi-static" data such as the locations of parks, CSVs of reference lists, etc.
|
||||
# This has an expiry time of 30 days, so will re-request from the source after that amount
|
||||
# of time has passed. This is used throughout Spothole to cache data that does not change
|
||||
# rapidly.
|
||||
SEMI_STATIC_URL_DATA_CACHE = CachedSession("cache/semi_static_url_data_cache",
|
||||
expire_after=timedelta(days=30))
|
||||
# rapidly. The ThreadSafeSession construct here protects it against some multithreading
|
||||
# contention weirdness we sometimes used to see on startup where the cache was hammered
|
||||
# pretty hard.
|
||||
_session = CachedSession("cache/semi_static_url_data_cache", expire_after=timedelta(days=30))
|
||||
_lock = threading.Lock()
|
||||
|
||||
|
||||
class _ThreadSafeSession:
|
||||
"""Wraps CachedSession with a lock to prevent concurrent SQLite access across threads."""
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
with _lock:
|
||||
return _session.get(*args, **kwargs)
|
||||
|
||||
|
||||
SEMI_STATIC_URL_DATA_CACHE = _ThreadSafeSession()
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script src="/js/add-spot.js?v=1782075686"></script>
|
||||
<script src="/js/add-spot.js?v=1782076050"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-add-spot").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script src="/js/alerts.js?v=1782075686"></script>
|
||||
<script src="/js/alerts.js?v=1782076050"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-alerts").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -77,8 +77,8 @@
|
||||
<script>
|
||||
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
|
||||
</script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782075686"></script>
|
||||
<script src="/js/bands.js?v=1782075686"></script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782076050"></script>
|
||||
<script src="/js/bands.js?v=1782076050"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-bands").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/css/style.css?v=1782075686" type="text/css">
|
||||
<link rel="stylesheet" href="/css/style.css?v=1782076050" type="text/css">
|
||||
<link href="/vendor/css/bootstrap-5.3.8.min.css" rel="stylesheet">
|
||||
<link href="/vendor/css/fontawesome-6.7.2.min.css" rel="stylesheet">
|
||||
<link href="/vendor/css/solid-6.7.2.min.css" rel="stylesheet">
|
||||
@@ -10,10 +10,10 @@
|
||||
<script src="/vendor/js/bootstrap-5.3.8.bundle.min.js"></script>
|
||||
<script src="/vendor/js/tinycolor2-1.6.0.min.js"></script>
|
||||
|
||||
<script src="/js/utils.js?v=1782075686"></script>
|
||||
<script src="/js/ui-ham.js?v=1782075686"></script>
|
||||
<script src="/js/geo.js?v=1782075686"></script>
|
||||
<script src="/js/common.js?v=1782075686"></script>
|
||||
<script src="/js/utils.js?v=1782076050"></script>
|
||||
<script src="/js/ui-ham.js?v=1782076050"></script>
|
||||
<script src="/js/geo.js?v=1782076050"></script>
|
||||
<script src="/js/common.js?v=1782076050"></script>
|
||||
{% end %}
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
|
||||
@@ -284,7 +284,7 @@
|
||||
</div>
|
||||
|
||||
<script src="/vendor/js/chart-4.4.9.umd.min.js"></script>
|
||||
<script src="/js/conditions.js?v=1782075686"></script>
|
||||
<script src="/js/conditions.js?v=1782076050"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-conditions").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -95,8 +95,8 @@
|
||||
<script>
|
||||
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
|
||||
</script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782075686"></script>
|
||||
<script src="/js/map.js?v=1782075686"></script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782076049"></script>
|
||||
<script src="/js/map.js?v=1782076049"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-map").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -116,8 +116,8 @@
|
||||
<script>
|
||||
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
|
||||
</script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782075686"></script>
|
||||
<script src="/js/spots.js?v=1782075686"></script>
|
||||
<script src="/js/spotsbandsandmap.js?v=1782076049"></script>
|
||||
<script src="/js/spots.js?v=1782076049"></script>
|
||||
<script>$(document).ready(function () {
|
||||
$("#nav-link-spots").addClass("active");
|
||||
}); <!-- highlight active page in nav --></script>
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/js/status.js?v=1782075686"></script>
|
||||
<script src="/js/status.js?v=1782076050"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#nav-link-status").addClass("active");
|
||||
|
||||
Reference in New Issue
Block a user