File tree 1 file changed +12
-1
lines changed
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
from django .conf import settings
4
4
from django .db .models import signals
5
-
5
+ from django . utils . timezone import now
6
6
7
7
site_url = urlsplit (settings .SITEURL )
8
8
11
11
12
12
class ProxyUrlsRegistry :
13
13
_first_init = True
14
+ _last_registry_load = None
15
+ _registry_reload_threshold = getattr (settings , "PROXY_RELOAD_REGISTRY_THRESHOLD_DAYS" , 1 )
14
16
15
17
def initialize (self ):
16
18
from geonode .base .models import Link
@@ -30,12 +32,16 @@ def initialize(self):
30
32
signals .post_delete .connect (link_post_delete , sender = Link )
31
33
self ._first_init = False
32
34
35
+ self ._last_registry_load = now ()
36
+
33
37
def set (self , hosts ):
34
38
self .proxy_allowed_hosts = set (hosts )
39
+ self ._last_registry_load = now ()
35
40
return self
36
41
37
42
def clear (self ):
38
43
self .proxy_allowed_hosts = set ()
44
+ self ._last_registry_load = now ()
39
45
return self
40
46
41
47
def register_host (self , host ):
@@ -45,6 +51,11 @@ def unregister_host(self, host):
45
51
self .proxy_allowed_hosts .remove (host )
46
52
47
53
def get_proxy_allowed_hosts (self ):
54
+ if (
55
+ self ._last_registry_load is None
56
+ or (now () - self ._last_registry_load ).days >= self ._registry_reload_threshold
57
+ ):
58
+ self .initialize ()
48
59
return self .proxy_allowed_hosts
49
60
50
61
You can’t perform that action at this time.
0 commit comments