Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Adding cache of path calculation and adding depth as indexed value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Navarro Bosch committed Jan 3, 2017
1 parent 15906b6 commit 3955d84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plone.server/plone/server/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@


def get_physical_path(context):
if hasattr(context, '_v_physical_path'):
return context._v_physical_path
parts = [context.__name__]
parent = context.__parent__
while parent is not None and parent.__name__ is not None:
parts.append(parent.__name__)
parent = parent.__parent__
parts.append('')
return reversed(parts)
context._v_physical_path = reversed(parts)
return context._v_physical_path


@adapter(IResource, IRequest)
Expand Down
6 changes: 6 additions & 0 deletions src/plone.server/plone/server/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from plone.server.security import get_principals_with_access_content
from plone.server.security import get_roles_with_access_content
from plone.server.utils import get_content_path
from plone.server.utils import get_content_depth
from zope.securitypolicy.rolepermission import rolePermissionManager
from zope.securitypolicy.settings import Allow
from zope.securitypolicy.settings import Deny
Expand Down Expand Up @@ -66,6 +67,11 @@ def get_path(ob):
return get_content_path(ob)


@index.with_accessor(IResource, 'depth', type='int')
def get_depth(ob):
return get_content_depth(ob)


@index.with_accessor(IResource, 'parent_uuid', type='keyword')
def get_parent_uuid(ob):
if hasattr(ob, '__parent__')\
Expand Down
12 changes: 12 additions & 0 deletions src/plone.server/plone/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,28 @@ def import_class(import_string):
def get_content_path(content):
""" No site id
"""
if hasattr(content, '_v_get_content_path'):
return '/' + '/'.join(reversed(content._v_get_content_path))
parts = []
parent = getattr(content, '__parent__', None)
while content is not None and content.__name__ is not None and\
parent is not None:
parts.append(content.__name__)
content = parent
parent = getattr(content, '__parent__', None)
content._v_get_content_path = parts
return '/' + '/'.join(reversed(parts))


def get_content_depth(content):
if hasattr(content, '_v_get_content_path'):
return len(content._v_get_content_path)
depth = 0
for parent in iter_parents(content):
depth += 1
return depth


def iter_parents(content):
content = getattr(content, '__parent__', None)
while content:
Expand Down

0 comments on commit 3955d84

Please sign in to comment.