File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from django .conf import settings
44from django .db .models import signals
5-
5+ from django . utils . timezone import now
66
77site_url = urlsplit (settings .SITEURL )
88
1111
1212class ProxyUrlsRegistry :
1313 _first_init = True
14+ _last_registry_load = None
15+ _registry_reload_threshold = getattr (settings , "PROXY_RELOAD_REGISTRY_THRESHOLD_DAYS" , 1 )
1416
1517 def initialize (self ):
1618 from geonode .base .models import Link
@@ -30,12 +32,16 @@ def initialize(self):
3032 signals .post_delete .connect (link_post_delete , sender = Link )
3133 self ._first_init = False
3234
35+ self ._last_registry_load = now ()
36+
3337 def set (self , hosts ):
3438 self .proxy_allowed_hosts = set (hosts )
39+ self ._last_registry_load = now ()
3540 return self
3641
3742 def clear (self ):
3843 self .proxy_allowed_hosts = set ()
44+ self ._last_registry_load = now ()
3945 return self
4046
4147 def register_host (self , host ):
@@ -45,6 +51,11 @@ def unregister_host(self, host):
4551 self .proxy_allowed_hosts .remove (host )
4652
4753 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 ()
4859 return self .proxy_allowed_hosts
4960
5061
You can’t perform that action at this time.
0 commit comments