Skip to content

Commit

Permalink
[Fixes #2] Severe performance issue when fetching resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Sep 18, 2019
1 parent f9953b8 commit 9b9e25d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/geoserver/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ def get_resources(self, names=None, stores=None, workspaces=None):
'''
if not stores:
_stores = self.get_stores(
names=names,
workspaces=workspaces
)
elif not isinstance(stores, list):
Expand Down
11 changes: 9 additions & 2 deletions src/geoserver/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
except:
from urlparse import urljoin

from geoserver.support import ResourceInfo, xml_property, write_bool, workspace_from_url
from geoserver.support import (
ResourceInfo,
xml_property,
write_bool,
workspace_from_url,
resource_from_url)
from geoserver.style import Style


Expand Down Expand Up @@ -134,7 +139,9 @@ def resource(self):
if self.gs_version >= "2.13":
if ":" in name:
ws_name, name = name.split(':')
return self.catalog.get_resources(names=name, workspaces=ws_name)[0]
store_name = resource_from_url(atom_link[0].get('href'), ws_name)
_resources = self.catalog.get_resources(names=[name], stores=[store_name], workspaces=[ws_name])
return _resources[0] if len(_resources) > 0 else _resources

def _get_default_style(self):
if 'default_style' in self.dirty:
Expand Down
10 changes: 10 additions & 0 deletions src/geoserver/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,13 @@ def workspace_from_url(url):
return split_path[split_path.index('workspaces') + 1]
else:
return None


def resource_from_url(url, workspace):
parts = urlparse(url)
split_path = parts.path.split('/')
if workspace in split_path:
resource_type = split_path[split_path.index(workspace) + 1]
return split_path[split_path.index(resource_type) + 1]
else:
return None

0 comments on commit 9b9e25d

Please sign in to comment.