Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
- Loading branch information
Jim Fulton
committed
Jul 17, 2016
1 parent
61af558
commit 04028a0
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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), | ||
]) | ||
|
||
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()) | ||
|
||
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()) | ||
|
||
|
||
def test_suite(): | ||
return unittest.makeSuite(PrefetchTests) |