Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
ac7443e2
Commit
ac7443e2
authored
Jul 21, 2016
by
Jim Fulton
Committed by
GitHub
Jul 21, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #92 from zopefoundation/prefetch
Added a connection prefetch method
parents
61af5586
7875e65b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
0 deletions
+122
-0
CHANGES.rst
CHANGES.rst
+15
-0
src/ZODB/Connection.py
src/ZODB/Connection.py
+21
-0
src/ZODB/interfaces.py
src/ZODB/interfaces.py
+18
-0
src/ZODB/mvccadapter.py
src/ZODB/mvccadapter.py
+9
-0
src/ZODB/tests/test_prefetch.py
src/ZODB/tests/test_prefetch.py
+59
-0
No files found.
CHANGES.rst
View file @
ac7443e2
...
...
@@ -2,6 +2,21 @@
Change History
================
5.0.0a6 (unreleased)
====================
- Added a connection ``prefetch`` method that can be used to request
that a storage prefect data an application will need::
conn.prefetch(obj, ...)
Where arguments can be objects, object ids, or iterables of objects
or object ids.
Added optional ``prefetch`` methods to the storage APIs. If a
storage doesn't support prefetch, then the connection prefetch
method is a noop.
5.0.0a5 (2016-07-06)
====================
...
...
src/ZODB/Connection.py
View file @
ac7443e2
...
...
@@ -1080,6 +1080,27 @@ class Connection(ExportImport, object):
# Savepoint support
#####################################################################
def
prefetch
(
self
,
*
args
):
try
:
self
.
_storage
.
prefetch
(
self
.
_prefetch_flatten
(
args
))
except
AttributeError
:
if
not
hasattr
(
self
.
_storage
,
'prefetch'
):
self
.
prefetch
=
lambda
*
a
:
None
else
:
raise
def
_prefetch_flatten
(
self
,
args
):
for
arg
in
args
:
if
isinstance
(
arg
,
bytes
):
yield
arg
elif
hasattr
(
arg
,
'_p_oid'
):
yield
arg
.
_p_oid
else
:
for
ob
in
arg
:
if
isinstance
(
ob
,
bytes
):
yield
ob
else
:
yield
ob
.
_p_oid
@
implementer
(
IDataManagerSavepoint
)
class
Savepoint
:
...
...
src/ZODB/interfaces.py
View file @
ac7443e2
...
...
@@ -754,6 +754,16 @@ class IStorage(Interface):
"""
class
IPrefetchStorage
(
IStorage
):
def
prefetch
(
oids
,
tid
):
"""Prefetch data for the given object ids before the given tid
The oids argument is an iterable that should be iterated no
more than once.
"""
class
IMultiCommitStorage
(
IStorage
):
"""A multi-commit storage can commit multiple transactions at once.
...
...
@@ -1112,6 +1122,14 @@ class IMVCCStorage(IStorage):
A POSKeyError is raised if there is no record for the object id.
"""
class
IMVCCPrefetchStorage
(
IMVCCStorage
):
def
prefetch
(
oids
):
"""Prefetch data for the given object ids
The oids argument is an iterable that should be iterated no
more than once.
"""
class
IStorageCurrentRecordIteration
(
IStorage
):
...
...
src/ZODB/mvccadapter.py
View file @
ac7443e2
...
...
@@ -146,6 +146,15 @@ class MVCCAdapterInstance(Base):
raise
POSException
.
ReadConflictError
(
repr
(
oid
))
return
r
[:
2
]
def
prefetch
(
self
,
oids
):
try
:
self
.
_storage
.
prefetch
(
oids
,
self
.
_start
)
except
AttributeError
:
if
not
hasattr
(
self
.
_storage
,
'prefetch'
):
self
.
prefetch
=
lambda
*
a
:
None
else
:
raise
_modified
=
None
# Used to keep track of oids modified within a
# transaction, so we can invalidate them later.
...
...
src/ZODB/tests/test_prefetch.py
0 → 100644
View file @
ac7443e2
import
unittest
from
ZODB.utils
import
z64
,
u64
import
ZODB
from
.MVCCMappingStorage
import
MVCCMappingStorage
class
PrefetchTests
(
unittest
.
TestCase
):
def
test_prefetch
(
self
):
db
=
ZODB
.
DB
(
None
)
fetched
=
[]
def
prefetch
(
oids
,
tid
):
fetched
.
append
((
list
(
map
(
u64
,
oids
)),
tid
))
db
.
storage
.
prefetch
=
prefetch
with
db
.
transaction
()
as
conn
:
for
i
in
range
(
10
):
conn
.
root
()[
i
]
=
conn
.
root
().
__class__
()
conn
=
db
.
open
()
conn
.
prefetch
(
z64
)
conn
.
prefetch
([
z64
])
conn
.
prefetch
(
conn
.
root
())
conn
.
prefetch
(
z64
,
(
conn
.
root
()[
i
]
for
i
in
range
(
3
)),
conn
.
root
()[
3
])
self
.
assertEqual
(
fetched
,
[([
0
],
conn
.
_storage
.
_start
),
([
0
],
conn
.
_storage
.
_start
),
([
0
],
conn
.
_storage
.
_start
),
([
0
,
1
,
2
,
3
,
4
],
conn
.
_storage
.
_start
),
])
db
.
close
()
def
test_prefetch_optional
(
self
):
conn
=
ZODB
.
connection
(
None
)
conn
.
prefetch
(
z64
)
conn
.
prefetch
([
z64
])
conn
.
prefetch
(
conn
.
root
())
conn
.
prefetch
(
z64
,
[
z64
])
conn
.
prefetch
(
z64
,
[
z64
],
conn
.
root
())
conn
.
close
()
def
test_prefetch_optional_imvcc
(
self
):
conn
=
ZODB
.
connection
(
MVCCMappingStorage
())
conn
.
prefetch
(
z64
)
conn
.
prefetch
([
z64
])
conn
.
prefetch
(
conn
.
root
())
conn
.
prefetch
(
z64
,
[
z64
])
conn
.
prefetch
(
z64
,
[
z64
],
conn
.
root
())
conn
.
close
()
def
test_suite
():
return
unittest
.
makeSuite
(
PrefetchTests
)
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