Commit c19dc4ff authored by Byron Jones's avatar Byron Jones

Bug 993926: Bugzilla::User::Setting::get_all_settings() should use memcached

r=sgreen,a=glob
parent 8b989123
...@@ -254,10 +254,13 @@ sub _get { ...@@ -254,10 +254,13 @@ sub _get {
elsif (ref($value) eq 'ARRAY') { elsif (ref($value) eq 'ARRAY') {
foreach my $value (@$value) { foreach my $value (@$value) {
next unless defined $value; next unless defined $value;
# arrays of hashes are common # arrays of hashes and arrays are common
if (ref($value) eq 'HASH') { if (ref($value) eq 'HASH') {
_detaint_hashref($value); _detaint_hashref($value);
} }
elsif (ref($value) eq 'ARRAY') {
_detaint_arrayref($value);
}
elsif (!ref($value)) { elsif (!ref($value)) {
trick_taint($value); trick_taint($value);
} }
...@@ -278,6 +281,15 @@ sub _detaint_hashref { ...@@ -278,6 +281,15 @@ sub _detaint_hashref {
} }
} }
sub _detaint_arrayref {
my ($arrayref) = @_;
foreach my $value (@$arrayref) {
if (defined($value) && !ref($value)) {
trick_taint($value);
}
}
}
sub _delete { sub _delete {
my ($self, $key) = @_; my ($self, $key) = @_;
$key = $self->_encode_key($key) $key = $self->_encode_key($key)
......
...@@ -15,8 +15,12 @@ use parent qw(Exporter); ...@@ -15,8 +15,12 @@ use parent qw(Exporter);
# Module stuff # Module stuff
@Bugzilla::User::Setting::EXPORT = qw(get_all_settings get_defaults @Bugzilla::User::Setting::EXPORT = qw(
add_setting); get_all_settings
get_defaults
add_setting
clear_settings_cache
);
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Util qw(trick_taint get_text); use Bugzilla::Util qw(trick_taint get_text);
...@@ -159,15 +163,20 @@ sub get_all_settings { ...@@ -159,15 +163,20 @@ sub get_all_settings {
my $settings = {}; my $settings = {};
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $rows = $dbh->selectall_arrayref( my $cache_key = "user_settings.$user_id";
q{SELECT name, default_value, is_enabled, setting_value, subclass my $rows = Bugzilla->memcached->get_config({ key => $cache_key });
FROM setting if (!$rows) {
LEFT JOIN profile_setting $rows = $dbh->selectall_arrayref(
ON setting.name = profile_setting.setting_name q{SELECT name, default_value, is_enabled, setting_value, subclass
AND profile_setting.user_id = ?}, undef, ($user_id)); 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) { 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; my $is_default;
...@@ -179,13 +188,18 @@ sub get_all_settings { ...@@ -179,13 +188,18 @@ sub get_all_settings {
} }
$settings->{$name} = new Bugzilla::User::Setting( $settings->{$name} = new Bugzilla::User::Setting(
$name, $user_id, $is_enabled, $name, $user_id, $is_enabled,
$default_value, $value, $is_default, $subclass); $default_value, $value, $is_default, $subclass);
} }
return $settings; return $settings;
} }
sub clear_settings_cache {
my ($user_id) = @_;
Bugzilla->memcached->clear_config({ key => "user_settings.$user_id" });
}
sub get_defaults { sub get_defaults {
my ($user_id) = @_; my ($user_id) = @_;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
...@@ -368,6 +382,13 @@ Params: C<$setting_name> - string - the name of the setting ...@@ -368,6 +382,13 @@ Params: C<$setting_name> - string - the name of the setting
C<$is_enabled> - boolean - if false, all users must use the global default C<$is_enabled> - boolean - if false, all users must use the global default
Returns: nothing 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 =begin private
=item C<_setting_exists> =item C<_setting_exists>
......
...@@ -53,6 +53,7 @@ if ($action eq 'update') { ...@@ -53,6 +53,7 @@ if ($action eq 'update') {
} }
$vars->{'message'} = 'default_settings_updated'; $vars->{'message'} = 'default_settings_updated';
$vars->{'changes_saved'} = $changed; $vars->{'changes_saved'} = $changed;
Bugzilla->memcached->clear_config();
delete_token($token); delete_token($token);
} }
......
...@@ -19,6 +19,7 @@ use Bugzilla::Util; ...@@ -19,6 +19,7 @@ use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::User::APIKey; use Bugzilla::User::APIKey;
use Bugzilla::User::Setting qw(clear_settings_cache);
use Bugzilla::Token; use Bugzilla::Token;
my $template = Bugzilla->template; my $template = Bugzilla->template;
...@@ -170,6 +171,7 @@ sub SaveSettings { ...@@ -170,6 +171,7 @@ sub SaveSettings {
} }
} }
$vars->{'settings'} = $user->settings(1); $vars->{'settings'} = $user->settings(1);
clear_settings_cache($user->id);
} }
sub DoEmail { sub DoEmail {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment