diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 7fd0eb70..0b2e1206 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -793,6 +793,12 @@ class Server(object): additional_request_data = kwargs.get("_additional_request_data", dict()) kwargs = dict((k, v) for k, v in kwargs.items() if not k.startswith("_") and not k == "plugin") kwargs.update(additional_request_data) + + base_url = kwargs.get("base_url", "") + if not (base_url.startswith("http://") or base_url.startswith("https://")): + self._logger.info("Skipping preemptive cache entry with base url {}, neither http:// nor https:// and possibly broken".format(base_url)) + continue + try: if plugin: self._logger.info("Preemptively caching {} (plugin {}) for {!r}".format(route, plugin, kwargs)) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 68f25703..4f6b3dbe 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -488,6 +488,12 @@ class PreemptiveCache(object): return matched, unmatched with self._lock: + if not self._log_access: + self._logger.debug( + "Not updating timestamp and counter for {} and {!r}, currently flagged as disabled".format(root, + data)) + return + cache_data = self.get_all_data() if not root in cache_data: @@ -509,12 +515,10 @@ class PreemptiveCache(object): to_persist["_timestamp"] = time.time() to_persist["_count"] = 1 self._logger.info("Adding entry for {} and {!r}".format(root, to_persist)) - elif self._log_access: + else: to_persist["_timestamp"] = time.time() to_persist["_count"] = to_persist.get("_count", 0) + 1 self._logger.debug("Updating timestamp and counter for {} and {!r}".format(root, data)) - else: - self._logger.debug("Not updating timestamp and counter for {} and {!r}, currently flagged as disabled".format(root, data)) self.set_data(root, [to_persist] + other) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 3b74bb74..6140eb4c 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -32,7 +32,7 @@ _valid_div_re = re.compile("[a-zA-Z_-]+") @app.route("/") @util.flask.preemptively_cached(cache=preemptiveCache, data=lambda: dict(path=request.path, base_url=request.url_root, query_string="l10n={}".format(g.locale.language) if g.locale else "en"), - unless=lambda: request.url_root in settings().get(["server", "preemptiveCache", "exceptions"])) + unless=lambda: request.url_root in settings().get(["server", "preemptiveCache", "exceptions"]) or not (request.url_root.startswith("http://") or request.url_root.startswith("https://"))) @util.flask.conditional(lambda: _check_etag_and_lastmodified_for_index(), NOT_MODIFIED) @util.flask.cached(timeout=-1, refreshif=lambda cached: _validate_cache_for_index(cached),