Ok, have made patch https://reviews.mahara.org/#/c/9950/
And tested in the following way: // Old way $stime = time(); log_debug('start: ' . $stime); for ($i = 1; $i <= 10000; $i++) { require_once('ddl.php'); $table = new XMLDBTable('view_access'); $field = new XMLDBField('id'); if (field_exists($table, $field)) { } if (($i % 1000) == 0) { log_debug('.'); } } $etime = time(); log_debug('end: ' . $etime); log_debug($etime - $stime); had time diff of approx 130 seconds per run for postgres had time diff of approx 90 seconds per run for mysql // vs New way $stime = time(); log_debug('start: ' . $stime); for ($i = 1; $i <= 10000; $i++) { if (column_exists('view_access', 'id')) { } if (($i % 1000) == 0) { log_debug('.'); } } $etime = time(); log_debug('end: ' . $etime); log_debug($etime - $stime); had time diff of approx 40 seconds for postgres had time diff of approx 4 seconds for mysql -- You received this bug notification because you are a member of Mahara Contributors, which is subscribed to Mahara. Matching subscriptions: Subscription for all Mahara Contributors -- please ask on #mahara-dev or mahara.org forum before editing or unsubscribing it! https://bugs.launchpad.net/bugs/1827445 Title: Improve efficiency when checking if a table field exists Status in Mahara: In Progress Bug description: When upgrading we use a field_exists() check to see if a table has a certain column or not which is fine there as upgrade chunks are a one- time execution run when users are all logged out. However we have begun to use field_exists() within other parts of the code and so this can get called on every page load by multiple users at once. This requires fetching the ddl.lib file and setting ul an XMLDB table object and an XMLDB field object which has overhead. Instead we should just query the database directly and ask it if the table has the column or not So instead of doing: require_once('ddl.php'); $table = new XMLDBTable('tablename'); $field = new XMLDBField('fieldname'); if (field_exists($table, $field)) { ... } We could just do: if (column_exists('tablename', 'fieldname')) { ... } And have the column_exists function that call the database directly To manage notifications about this bug go to: https://bugs.launchpad.net/mahara/+bug/1827445/+subscriptions _______________________________________________ Mailing list: https://launchpad.net/~mahara-contributors Post to : mahara-contributors@lists.launchpad.net Unsubscribe : https://launchpad.net/~mahara-contributors More help : https://help.launchpad.net/ListHelp