propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

load table maps lazily #1902

Closed mringler closed 2 years ago

mringler commented 2 years ago

fixes #1901

When adding table classes to a Propel database object, currently those classes are immediately instantiated, event though many of those classes will not be used in one cycle, leading to unnecessary overhead, particularly on databases with lots of tables.

A simple fix is to add tables as class strings, and only instantiate them when they are actually used.

The way it is implemented here, the $tables and $tablesByPhpName properties of DatabaseMap now can contain both TableMap objects or class strings, which is not ideal, but it seems to be the most seamless integration of this change. Let me know if there is a better way.

codecov-commenter commented 2 years ago

Codecov Report

Merging #1902 (26eea73) into master (4e59c81) will increase coverage by 0.02%. The diff coverage is 96.00%.

@@             Coverage Diff              @@
##             master    #1902      +/-   ##
============================================
+ Coverage     87.61%   87.64%   +0.02%     
- Complexity     7818     7826       +8     
============================================
  Files           227      227              
  Lines         21161    21180      +19     
============================================
+ Hits          18540    18563      +23     
+ Misses         2621     2617       -4     
Flag Coverage Δ
5-max 87.64% <96.00%> (+0.02%) :arrow_up:
7.4 87.64% <96.00%> (+0.02%) :arrow_up:
agnostic 67.03% <96.00%> (+0.04%) :arrow_up:
mysql 68.86% <52.00%> (-0.01%) :arrow_down:
pgsql 68.88% <52.00%> (-0.01%) :arrow_down:
sqlite 66.70% <52.00%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Propel/Runtime/Map/DatabaseMap.php 89.70% <95.45%> (+11.27%) :arrow_up:
...rc/Propel/Generator/Builder/Om/TableMapBuilder.php 95.28% <100.00%> (+<0.01%) :arrow_up:
...time/ServiceContainer/StandardServiceContainer.php 86.98% <100.00%> (ø)
src/Propel/Common/Util/SetColumnConverter.php 100.00% <0.00%> (ø)
src/Propel/Generator/Manager/AbstractManager.php 77.20% <0.00%> (ø)
...l/Generator/Behavior/Delegate/DelegateBehavior.php 90.22% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

profuel commented 2 years ago

Local testing with 350 tables: initDatabaseMaps is executed almost twice faster with this fix. Execution time of the rest of code didn't change