Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
_system_theme_data() reads theme files from the disk and executes drupal_alter.
On a system with many modules and/or themes this adds a performance hit.
Replacing _system_theme_data() with a DB read of the system table (as done in common.inc's list_themes()) can greatly improve performance.
$result = db_query("SELECT * FROM {system} WHERE type = '%s'", 'theme');
while ($theme = db_fetch_object($result)) {
if (file_exists($theme->filename)) {
$theme->info = unserialize($theme->info);
$themes[] = $theme;
}
}
is around 40-50x faster than
_system_theme_data()
Patch follows.
Comment | File | Size | Author |
---|---|---|---|
#7 | skinr-replace_system_theme_data-1129746-7.patch | 1.31 KB | moonray |
#1 | skinr-system-theme-data-1129746-1.patch | 1.53 KB | setvik |
Comments
Comment #1
setvik CreditAttribution: setvik commentedComment #2
Peter Bowey CreditAttribution: Peter Bowey commentedRefer #1
I like it: +1 rating
Good lateral thinking setvik
I had several issues with the
private _system_theme_data()
methodused in skinr 6.x-1.x-dev
Comment #3
moonray CreditAttribution: moonray commentedAlso see #943782: _system_theme_data() causes PHP notices, but system_theme_data() causes themes to be disabled on update
Comment #4
Peter Bowey CreditAttribution: Peter Bowey commentedI have updated your patch in #1:
I was getting PHP E-Notices: ==>
Notice: Trying to get property of non-object in system_find_base_themes()
New code (below):
I no longer see PHP 5.3.x 'E-Notice' reports via Pressflow 6.22.
Comment #6
moonray CreditAttribution: moonray commented@Peter Bowey How is this different from just calling list_themes()?
Comment #7
moonray CreditAttribution: moonray commentedUsing list_themes() instead of system_theme_data() speeds things up a lot. No need for custom function.
Comment #9
moonray CreditAttribution: moonray commented