diff options
author | Byron Jones <glob@mozilla.com> | 2014-08-12 08:09:46 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2014-08-12 08:09:46 +0200 |
commit | bc450dc015ffc325b10d9ffdf59a9b00f82cf70f (patch) | |
tree | cd1a476c6d816a883ae8a6477b15bc9e4e7c8d30 /Bugzilla/User | |
parent | 2f5c78b7362cc604f341bb1d3a2c4d486f19ce5c (diff) | |
download | bugzilla-bc450dc015ffc325b10d9ffdf59a9b00f82cf70f.tar.gz bugzilla-bc450dc015ffc325b10d9ffdf59a9b00f82cf70f.tar.xz |
Bug 993926: Bugzilla::User::Setting::get_all_settings() should use memcached
Diffstat (limited to 'Bugzilla/User')
-rw-r--r-- | Bugzilla/User/Setting.pm | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/Bugzilla/User/Setting.pm b/Bugzilla/User/Setting.pm index 27470f435..e083a251e 100644 --- a/Bugzilla/User/Setting.pm +++ b/Bugzilla/User/Setting.pm @@ -25,8 +25,12 @@ use base qw(Exporter); # Module stuff -@Bugzilla::User::Setting::EXPORT = qw(get_all_settings get_defaults - add_setting); +@Bugzilla::User::Setting::EXPORT = qw( + get_all_settings + get_defaults + add_setting + clear_settings_cache +); use Bugzilla::Error; use Bugzilla::Util qw(trick_taint get_text); @@ -169,15 +173,20 @@ sub get_all_settings { my $settings = {}; my $dbh = Bugzilla->dbh; - my $rows = $dbh->selectall_arrayref( - q{SELECT name, default_value, is_enabled, setting_value, subclass - FROM setting - LEFT JOIN profile_setting - ON setting.name = profile_setting.setting_name - AND profile_setting.user_id = ?}, undef, ($user_id)); + my $cache_key = "user_settings.$user_id"; + my $rows = Bugzilla->memcached->get_config({ key => $cache_key }); + if (!$rows) { + $rows = $dbh->selectall_arrayref( + q{SELECT name, default_value, is_enabled, setting_value, subclass + FROM setting + LEFT JOIN profile_setting + ON setting.name = profile_setting.setting_name + AND profile_setting.user_id = ?}, undef, ($user_id)); + Bugzilla->memcached->set_config({ key => $cache_key, data => $rows }); + } foreach my $row (@$rows) { - my ($name, $default_value, $is_enabled, $value, $subclass) = @$row; + my ($name, $default_value, $is_enabled, $value, $subclass) = @$row; my $is_default; @@ -189,13 +198,18 @@ sub get_all_settings { } $settings->{$name} = new Bugzilla::User::Setting( - $name, $user_id, $is_enabled, + $name, $user_id, $is_enabled, $default_value, $value, $is_default, $subclass); } return $settings; } +sub clear_settings_cache { + my ($user_id) = @_; + Bugzilla->memcached->clear_config({ key => "user_settings.$user_id" }); +} + sub get_defaults { my ($user_id) = @_; my $dbh = Bugzilla->dbh; @@ -378,6 +392,13 @@ Params: C<$setting_name> - string - the name of the setting C<$is_enabled> - boolean - if false, all users must use the global default Returns: nothing +=item C<clear_settings_cache($user_id)> + +Description: Clears cached settings data for the specified user. Must be + called after updating any user's setting. +Params: C<$user_id> - integer - the user id. +Returns: nothing + =begin private =item C<_setting_exists> |