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
Hide 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,15 +883,18 @@ 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
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
))
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,59 +35,8 @@ 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
()
@
classmethod
def
get
(
cls
,
key
):
return
cls
.
value
.
get
(
key
,
None
)
@
classmethod
def
set
(
cls
,
key
,
value
):
with
cls
.
lock
:
cls
.
value
[
key
]
=
value
@
classmethod
def
clear
(
cls
):
with
cls
.
lock
:
cls
.
value
=
{}
@
classmethod
def
load_default
(
cls
):
location
=
environ
.
get
(
'ZCATALOGQUERYPLAN'
)
if
location
:
try
:
pmap
=
resolve
(
location
)
logger
.
info
(
'loaded priority %d map(s) from %s'
,
len
(
pmap
),
location
)
# Convert simple benchmark tuples to namedtuples
new_plan
=
{}
for
querykey
,
details
in
pmap
.
items
():
new_plan
[
querykey
]
=
{}
for
indexname
,
benchmark
in
details
.
items
():
new_plan
[
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
(
object
):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to reports. The inner dict holds
a query key to Report mapping.
"""
lock
=
allocate_lock
()
value
=
{}
class
NestedDict
(
object
):
"""Holds a structure of two nested dicts."""
@
classmethod
def
get
(
cls
,
key
):
...
...
@@ -127,6 +76,54 @@ class Reports(object):
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'
)
if
location
:
try
:
pmap
=
resolve
(
location
)
logger
.
info
(
'loaded priority %d map(s) from %s'
,
len
(
pmap
),
location
)
# Convert the simple benchmark tuples to namedtuples
new_plan
=
{}
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
[
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
(
NestedDict
):
"""This holds a structure of nested dicts.
The outer dict is a mapping of catalog id to reports. The inner dict holds
a query key to Report mapping.
"""
lock
=
allocate_lock
()
value
=
{}
class
ValueIndexes
(
object
):
"""Holds a set of index names considered to have an uneven value
distribution.
...
...
@@ -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