important inefficiency on data fetching affects any database type

Bug #1525695 reported by Giovanni Pellerano
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

While working on GlobaLeaks and using Storm as ORM we encountered an important inefficiency on data fetching.

We are using SQLite but by a small code audit it seems that the inefficiency may affect any database as it applies generically to Storm.

Basically storm allows for each variable to define a default initializer function, but this initializer is always called even while the objects are fetched from the database.

Now suppose that by design every object has an id, that in a lot of databases is an uuid4 and binded to a os.urandom() function; what would happen if the database would be populated by 1000 entries is that the os.urandom() function will be called 1000 times even if there is no need at all to recall it.
This example is wantly related to globaleaks for a matter of exemplification but its clear that the bug would affect any kind of initializer that would be called anyway without reasons.

The issue lie in the following lines of variables.py:
125 if value is not Undef:
126 self.set(value, from_db)
127 elif value_factory is not Undef:
128 self.set(value_factory(), from_db)

the code would probably be refactored postponing such a call to a later stage where the function pointer can simply passed by to nested function and used if an only if there would be the need to.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.