Skip to content

Commit 25a5cb8

Browse files
author
Alexander Smishlajev
committed
if optimize is set, load the schema file in __init__()...
...and then use compiled code object to apply the schema when the database is open.
1 parent e43001d commit 25a5cb8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

roundup/instance.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: instance.py,v 1.30 2004-11-10 08:58:47 a1s Exp $
18+
# $Id: instance.py,v 1.31 2004-11-11 12:02:30 a1s Exp $
1919

2020
'''Tracker handling (open tracker).
2121
@@ -56,6 +56,13 @@ def __init__(self, tracker_home, optimize=0):
5656
# initialize tracker extensions
5757
for extension in self.get_extensions('extensions'):
5858
extension(self)
59+
# load database schema
60+
schemafilename = os.path.join(self.tracker_home, 'schema.py')
61+
# Note: can't use built-in open()
62+
# because of the global function with the same name
63+
schemafile = file(schemafilename, 'rt')
64+
self.schema = compile(schemafile.read(), schemafilename, 'exec')
65+
schemafile.close()
5966
# load database detectors
6067
self.detectors = self.get_extensions('detectors')
6168
# db_open is set to True after first open()
@@ -88,17 +95,20 @@ def open(self, name=None):
8895
'Number': hyperdb.Number,
8996
'db': backend.Database(self.config, name)
9097
}
91-
self._load_python('schema.py', vars)
92-
db = vars['db']
9398

9499
if self.optimize:
100+
# execute preloaded schema object
101+
exec(self.schema, vars)
95102
# use preloaded detectors
96103
detectors = self.detectors
97104
else:
105+
# execute the schema file
106+
self._load_python('schema.py', vars)
98107
# reload extensions and detectors
99108
for extension in self.get_extensions('extensions'):
100109
extension(self)
101110
detectors = self.get_extensions('detectors')
111+
db = vars['db']
102112
# apply the detectors
103113
for detector in detectors:
104114
detector(db)

0 commit comments

Comments
 (0)