summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/Memcached.pm14
-rw-r--r--Bugzilla/User/Setting.pm41
-rwxr-xr-xeditsettings.cgi1
-rwxr-xr-xuserprefs.cgi2
4 files changed, 47 insertions, 11 deletions
diff --git a/Bugzilla/Memcached.pm b/Bugzilla/Memcached.pm
index 28934e4f5..fdafa0014 100644
--- a/Bugzilla/Memcached.pm
+++ b/Bugzilla/Memcached.pm
@@ -261,10 +261,13 @@ sub _get {
elsif (ref($value) eq 'ARRAY') {
foreach my $value (@$value) {
next unless defined $value;
- # arrays of hashes are common
+ # arrays of hashes and arrays are common
if (ref($value) eq 'HASH') {
_detaint_hashref($value);
}
+ elsif (ref($value) eq 'ARRAY') {
+ _detaint_arrayref($value);
+ }
elsif (!ref($value)) {
trick_taint($value);
}
@@ -285,6 +288,15 @@ sub _detaint_hashref {
}
}
+sub _detaint_arrayref {
+ my ($arrayref) = @_;
+ foreach my $value (@$arrayref) {
+ if (defined($value) && !ref($value)) {
+ trick_taint($value);
+ }
+ }
+}
+
sub _delete {
my ($self, $key) = @_;
$key = $self->_encode_key($key)
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>
diff --git a/editsettings.cgi b/editsettings.cgi
index d375a3d5d..981495893 100755
--- a/editsettings.cgi
+++ b/editsettings.cgi
@@ -62,6 +62,7 @@ if ($action eq 'update') {
}
$vars->{'message'} = 'default_settings_updated';
$vars->{'changes_saved'} = $changed;
+ Bugzilla->memcached->clear_config();
delete_token($token);
}
diff --git a/userprefs.cgi b/userprefs.cgi
index a4083a981..d33de74ad 100755
--- a/userprefs.cgi
+++ b/userprefs.cgi
@@ -33,6 +33,7 @@ use Bugzilla::Search;
use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::User;
+use Bugzilla::User::Setting qw(clear_settings_cache);
use Bugzilla::Token;
my $template = Bugzilla->template;
@@ -185,6 +186,7 @@ sub SaveSettings {
}
}
$vars->{'settings'} = $user->settings(1);
+ clear_settings_cache($user->id);
}
sub DoEmail {