Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
0471cbd6
Commit
0471cbd6
authored
Aug 02, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actually nest the queryplan on the catalog id as well
parent
a370d541
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
61 deletions
+61
-61
src/Products/ZCatalog/ZCatalog.py
src/Products/ZCatalog/ZCatalog.py
+9
-6
src/Products/ZCatalog/plan.py
src/Products/ZCatalog/plan.py
+52
-55
No files found.
src/Products/ZCatalog/ZCatalog.py
View file @
0471cbd6
...
...
@@ -883,16 +883,19 @@ class ZCatalog(Folder, Persistent, Implicit):
security
.
declareProtected
(
manage_zcatalog_entries
,
'getCatalogPlan'
)
def
getCatalogPlan
(
self
):
"""Get a string representation of a query plan"""
p
lan
=
PriorityMap
.
get_plan
()
p
map
=
PriorityMap
.
get_value
()
output
=
[]
output
.
append
(
'# query plan dumped at %r
\
n
'
%
time
.
asctime
())
output
.
append
(
'queryplan = {'
)
for
cid
,
plan
in
sorted
(
pmap
.
items
()):
output
.
append
(
' %s: {'
%
repr
(
cid
))
for
querykey
,
details
in
sorted
(
plan
.
items
()):
output
.
append
(
' %s: {'
%
repr
(
querykey
))
for
indexname
,
benchmark
in
sorted
(
details
.
items
()):
tuplebench
=
repr
(
tuple
(
benchmark
))
output
.
append
(
' %r:
\
n
%s,'
%
(
indexname
,
tuplebench
))
output
.
append
(
' },'
)
output
.
append
(
' },'
)
output
.
append
(
'}'
)
return
'
\
n
'
.
join
(
output
)
...
...
src/Products/ZCatalog/plan.py
View file @
0471cbd6
...
...
@@ -35,19 +35,16 @@ Report = namedtuple('Report', ['hits', 'duration', 'last'])
logger
=
getLogger
(
'Products.ZCatalog'
)
class
PriorityMap
(
object
):
"""This holds a query key to Benchmark mapping."""
lock
=
allocate_lock
()
value
=
{}
@
classmethod
def
get_plan
(
cls
):
return
cls
.
value
.
copy
()
class
NestedDict
(
object
):
"""Holds a structure of two nested dicts."""
@
classmethod
def
get
(
cls
,
key
):
return
cls
.
value
.
get
(
key
,
None
)
outer
=
cls
.
value
.
get
(
key
,
None
)
if
outer
is
None
:
cls
.
set
(
key
,
{})
outer
=
cls
.
value
[
key
]
return
outer
@
classmethod
def
set
(
cls
,
key
,
value
):
...
...
@@ -59,6 +56,40 @@ class PriorityMap(object):
with
cls
.
lock
:
cls
.
value
=
{}
@
classmethod
def
get_entry
(
cls
,
key
,
key2
):
outer
=
cls
.
get
(
key
)
inner
=
outer
.
get
(
key2
,
None
)
if
inner
is
None
:
cls
.
set_entry
(
key
,
key2
,
{})
inner
=
outer
.
get
(
key2
)
return
inner
@
classmethod
def
set_entry
(
cls
,
key
,
key2
,
value
):
outer
=
cls
.
get
(
key
)
with
cls
.
lock
:
outer
[
key2
]
=
value
@
classmethod
def
clear_entry
(
cls
,
key
):
cls
.
set
(
key
,
{})
class
PriorityMap
(
NestedDict
):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to plans. The inner dict holds
a query key to Benchmark mapping.
"""
lock
=
allocate_lock
()
value
=
{}
@
classmethod
def
get_value
(
cls
):
return
cls
.
value
.
copy
()
@
classmethod
def
load_default
(
cls
):
location
=
environ
.
get
(
'ZCATALOGQUERYPLAN'
)
...
...
@@ -67,19 +98,22 @@ class PriorityMap(object):
pmap
=
resolve
(
location
)
logger
.
info
(
'loaded priority %d map(s) from %s'
,
len
(
pmap
),
location
)
# Convert simple benchmark tuples to namedtuples
# Convert
the
simple benchmark tuples to namedtuples
new_plan
=
{}
for
querykey
,
details
in
pmap
.
items
():
new_plan
[
querykey
]
=
{}
for
cid
,
plan
in
pmap
.
items
():
new_plan
[
cid
]
=
{}
for
querykey
,
details
in
plan
.
items
():
new_plan
[
cid
][
querykey
]
=
{}
for
indexname
,
benchmark
in
details
.
items
():
new_plan
[
querykey
][
indexname
]
=
Benchmark
(
*
benchmark
)
new_plan
[
cid
][
querykey
][
indexname
]
=
\
Benchmark
(
*
benchmark
)
with
cls
.
lock
:
cls
.
value
=
new_plan
except
ImportError
:
logger
.
warning
(
'could not load priority map from %s'
,
location
)
class
Reports
(
obje
ct
):
class
Reports
(
NestedDi
ct
):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to reports. The inner dict holds
...
...
@@ -89,43 +123,6 @@ class Reports(object):
lock
=
allocate_lock
()
value
=
{}
@
classmethod
def
get
(
cls
,
key
):
outer
=
cls
.
value
.
get
(
key
,
None
)
if
outer
is
None
:
cls
.
set
(
key
,
{})
outer
=
cls
.
value
[
key
]
return
outer
@
classmethod
def
set
(
cls
,
key
,
value
):
with
cls
.
lock
:
cls
.
value
[
key
]
=
value
@
classmethod
def
clear
(
cls
):
with
cls
.
lock
:
cls
.
value
=
{}
@
classmethod
def
get_entry
(
cls
,
key
,
key2
):
outer
=
cls
.
get
(
key
)
inner
=
outer
.
get
(
key2
,
None
)
if
inner
is
None
:
cls
.
set_entry
(
key
,
key2
,
{})
inner
=
outer
.
get
(
key2
)
return
inner
@
classmethod
def
set_entry
(
cls
,
key
,
key2
,
value
):
outer
=
cls
.
get
(
key
)
with
cls
.
lock
:
outer
[
key2
]
=
value
@
classmethod
def
clear_entry
(
cls
,
key
):
cls
.
set
(
key
,
{})
class
ValueIndexes
(
object
):
"""Holds a set of index names considered to have an uneven value
...
...
@@ -239,7 +236,7 @@ class CatalogPlan(object):
self
.
duration
=
None
def
plan
(
self
):
benchmark
=
PriorityMap
.
get
(
self
.
key
)
benchmark
=
PriorityMap
.
get
_entry
(
self
.
cid
,
self
.
key
)
if
not
benchmark
:
return
None
...
...
@@ -290,7 +287,7 @@ class CatalogPlan(object):
def
stop
(
self
):
self
.
end_time
=
time
.
time
()
self
.
duration
=
self
.
end_time
-
self
.
start_time
PriorityMap
.
set
(
self
.
key
,
self
.
benchmark
)
PriorityMap
.
set
_entry
(
self
.
cid
,
self
.
key
,
self
.
benchmark
)
self
.
log
()
def
log
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment