]> git.mjollnir.org Git - moodle.git/commit
get_string: Refactoring, performance improvements, bug fixes and unit tests
authortjhunt <tjhunt>
Mon, 30 Mar 2009 02:21:27 +0000 (02:21 +0000)
committertjhunt <tjhunt>
Mon, 30 Mar 2009 02:21:27 +0000 (02:21 +0000)
commitbb45fe62c497f20232d722f70da0faac9fc15aba
treecc1389c0cf0732cab71df6f8cf131fcc808b4621
parentedbc93a7e4c1b3d893c50ed5599eb469f813ddde
get_string: Refactoring, performance improvements, bug fixes and unit tests

MDL-18669 get_string refactored to elimiate duplicate code and make it easier to understand.
MDL-17763 parent language not processed correctly when getting a plugin string.
MDL-16181 more intelligent caching to avoid repeated file_exists checks.
MDL-12434 move values to array keys to improve lookup times.

The main part of the refactoring is to create a singleton string_manager class to encapsulate the cached data and the processing, while breaking the code up into more smaller methods.

Other performance improvements include:
* Cache results of plugin name -> locations to search array.
* Cache parent lang lookup.
* Skip eval if the string does not contain $ \ or %.
* Remove the unnecessary sprintf from the eval.

There is a performance testing script in lib/simpletest/getstringperformancetester.php. For now this script has the old get_string implementation copied and pasted to the end, and renamed to old_get_string to allow for comparitive timings.

There are now some unit tests for get_string in lib/simpletest/teststringmanager.php. I think I have managed to cover most of the tricky cases.
21 files changed:
help.php
lang/en_utf8/moodle.php
lib/moodlelib.php
lib/simpletest/get_string_fixtures/moodle/blocks/mrbs/lang/en_utf8/block_mrbs.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodle/blocks/mrbs/lang/fr_utf8/block_mrbs.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodle/lang/en_utf8/moodle.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodle/lang/en_utf8/test.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodle/lang/en_utf8_local/moodle.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodle/lang/es_ar_utf8_local/langconfig.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodledata/lang/es_ar_utf8/langconfig.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodledata/lang/fr_ca_utf8/langconfig.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodledata/lang/fr_ca_utf8/test.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/moodledata/lang/fr_utf8/test.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/pagelogs/admin_index.php_get_string.log.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/pagelogs/admin_index.php_old_get_string.log.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/pagelogs/course_view.php_get_string.log.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/pagelogs/course_view.php_old_get_string.log.php [new file with mode: 0644]
lib/simpletest/get_string_fixtures/pagelogs/empty.log.php [new file with mode: 0644]
lib/simpletest/getstringperformancetester.php [new file with mode: 0644]
lib/simpletest/testmoodlelib.php
lib/simpletest/teststringmanager.php [new file with mode: 0644]