set_config() writes to the database even if it's not necessary

Bug #1526073 reported by Aaron Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Aaron Wells

Bug Description

Mahara's set_config() methods updates the database every single time you call it, even if you haven't actually changed the value of the field.

It would be more efficient if it did not do this. Especially since it already does a SELECT statement to check whether it needs to do an UPDATE or INSERT, it would be trivial to also make it check to see if the value in the database is the same as the value passed by the user, and skip that UPDATE if so.

Tags: performance
Aaron Wells (u-aaronw)
Changed in mahara:
assignee: nobody → Aaron Wells (u-aaronw)
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/5850

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Since the only effect of these changes should be a silent reduction in the number of calls to set_field(), I wrote up a test script to help me with testing it. I've attached the test script here. You can apply it to your Mahara site by downloading it to a file called "testpatch.txt", and then applying it using the "patch" command:

cd /path/to/mahara
patch -p0 < /path/to/testpatch.txt

It causes the set_config* methods to be called with the same argument twice, using a number of different data types. It also adds a call to "debug_print_backtrace()" into set_field() to make it visible when it is being called.

To test with this:

1. Apply the patch as described above
2. In your web browser, navigate to <yourmaharasite>/test.php
3. Refresh the test.php page at least twice (the first time it runs it will insert these records rather than calling set_field(), making the results less apparent)

On a successful run, you should see stacktraces indicating that the set_field() was called 15 times (5 different config values x 3 different functions). You should see that it only ran on the first call with each config value, and not on the second call. You should not see any warning messages or error messages except for the stacktraces generated by the test script.

Aaron Wells (u-aaronw)
Changed in mahara:
milestone: 16.04.0 → 16.10.0
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/5850
Committed: https://git.mahara.org/mahara/mahara/commit/a79dd6bbeaee8f62ebeab6dfd697089cbfa1e1ca
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit a79dd6bbeaee8f62ebeab6dfd697089cbfa1e1ca
Author: Aaron Wells <email address hidden>
Date: Tue Dec 15 13:17:34 2015 +1300

Get rid of redundant DB writes in set_config()

Bug 1526073. Also in set_config_plugin() and
set_config_plugin_instance().

set_config_institution() is more complicated, and outside
the scope of this bug.

Change-Id: Ibaeb93fea83c190e6ffab7cd000eddf98f3afbb7
behatnotneeded: Covered by existing tests

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "16.10_STABLE" branch: https://reviews.mahara.org/6984

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/6984
Committed: https://git.mahara.org/mahara/mahara/commit/749ee8c247fa360a8ce9807fe91dd114f56a54e1
Submitter: Robert Lyon (<email address hidden>)
Branch: 16.10_STABLE

commit 749ee8c247fa360a8ce9807fe91dd114f56a54e1
Author: Aaron Wells <email address hidden>
Date: Tue Dec 15 13:17:34 2015 +1300

Get rid of redundant DB writes in set_config()

Bug 1526073. Also in set_config_plugin() and
set_config_plugin_instance().

set_config_institution() is more complicated, and outside
the scope of this bug.

Change-Id: Ibaeb93fea83c190e6ffab7cd000eddf98f3afbb7
behatnotneeded: Covered by existing tests
(cherry picked from commit a79dd6bbeaee8f62ebeab6dfd697089cbfa1e1ca)

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → Fix Released
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.