Back to index

plone3  3.1.7
testQuery.py
Go to the documentation of this file.
00001 import time
00002 import transaction
00003 import sys
00004 import os
00005 from os.path import realpath
00006 import math
00007 
00008 from ZODB import DB
00009 from ZODB.FileStorage import FileStorage
00010 
00011 from common import Root, Dummy
00012 
00013 NUM_ITER = 500
00014 
00015 epi_path = '/'.join(realpath(os.getcwd()).split('/')[:-1])
00016 sys.path.insert(0, epi_path)
00017 from ExtendedPathIndex import ExtendedPathIndex
00018 
00019 print '\nOpening file storage'
00020 
00021 storage = FileStorage(file_name='EPI.fs', create=False, read_only=True)
00022 db = DB(storage)
00023 
00024 transaction.begin()
00025 conn = db.open()
00026 root = conn.root()
00027 
00028 plone = root['plone']
00029 index = plone.index
00030 
00031 start = time.time()
00032 for i in range(NUM_ITER):
00033     res = index._apply_index({"path": {'query': '/plone', "depth": 2}})
00034 end = time.time()
00035 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00036                                                   end-start, NUM_ITER)
00037 res1 = res[0].keys()
00038 
00039 # Try not touching the /plone set as it contains 200820 entries
00040 start = time.time()
00041 for i in range(NUM_ITER):
00042     res = index._apply_index({"path": {'query': '/', "depth": 3, 'startlevel':1}})
00043 end = time.time()
00044 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00045                                                   end-start, NUM_ITER)
00046 res2 = res[0].keys()
00047 
00048 if res1 == res2:
00049     print "Results are the same"
00050 else:
00051     print "Different results!"
00052 
00053 print "\n============================"
00054 
00055 print "Navtree query at root"
00056 start = time.time()
00057 for i in range(NUM_ITER):
00058     res = index._apply_index({"path": {'query': '/plone', "navtree": 1}})
00059 end = time.time()
00060 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00061                                                   end-start, NUM_ITER)
00062 
00063 print "Navtree query at /plone/f-1/f-1-1/f-1-1-1"
00064 start = time.time()
00065 for i in range(NUM_ITER):
00066     res = index._apply_index({"path": {'query': '/plone/f-1/f-1-1/f-1-1-1', "navtree": 1}})
00067 end = time.time()
00068 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00069                                                   end-start, NUM_ITER)
00070 
00071 print "\n============================"
00072 
00073 print "Folder listing at portal root"
00074 start = time.time()
00075 for i in range(NUM_ITER):
00076     res = index._apply_index({"path": {'query': '/plone', "depth": 1}})
00077 end = time.time()
00078 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00079                                                   end-start, NUM_ITER)
00080 
00081 print "Folder listing at /plone/f-1"
00082 start = time.time()
00083 for i in range(NUM_ITER):
00084     res = index._apply_index({"path": {'query': '/plone/f-1', "depth": 1}})
00085 end = time.time()
00086 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00087                                                   end-start, NUM_ITER)
00088 
00089 print "\n============================"
00090 
00091 print "Breadcrumbs at portal root"
00092 start = time.time()
00093 for i in range(NUM_ITER):
00094     res = index._apply_index({"path": {'query': '/plone', "depth": 0,
00095                                        "navtree": 1}})
00096 end = time.time()
00097 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00098                                                   end-start, NUM_ITER)
00099 
00100 print "Breadcrumbs at /plone/f-1/f-1-1/f-1-1-1"
00101 start = time.time()
00102 for i in range(NUM_ITER):
00103     res = index._apply_index({"path": {'query': '/plone/f-1/f-1-1/f-1-1-1',
00104                                        "depth": 0, "navtree": 1}})
00105 end = time.time()
00106 print 'Found %s in %s seconds (%s iterations)' % (len(res[0].keys()),
00107                                                   end-start, NUM_ITER)
00108 
00109 transaction.abort()
00110 conn.close()
00111 
00112 db.close()
00113 storage.close()
00114 #storage.cleanup() # For removing all files