4 |
4 |
use Carp;
|
5 |
5 |
use Data::Dumper;
|
6 |
6 |
use List::Util qw(first);
|
7 |
|
use List::UtilsBy qw(sort_by);
|
|
7 |
use List::UtilsBy qw(sort_by partition_by);
|
8 |
8 |
|
9 |
9 |
use constant META_CVARS => 'cvars_config';
|
10 |
10 |
|
... | ... | |
84 |
84 |
my $configs = _all_configs(%params);
|
85 |
85 |
my $cvars = $self->custom_variables;
|
86 |
86 |
my %cvars_by_config = map { $_->config_id => $_ } @$cvars;
|
|
87 |
my $invalids = _all_invalids($self->${\ $self->meta->primary_key_columns->[0]->name }, $configs, %params);
|
|
88 |
my %invalids_by_config = map { $_->config_id => 1 } @$invalids;
|
87 |
89 |
|
88 |
90 |
my @return = map(
|
89 |
91 |
{
|
|
92 |
my $cvar;
|
90 |
93 |
if ( $cvars_by_config{$_->id} ) {
|
91 |
|
$cvars_by_config{$_->id};
|
|
94 |
$cvar = $cvars_by_config{$_->id};
|
|
95 |
$cvar->{is_valid} = !$invalids_by_config{$_->id};
|
92 |
96 |
}
|
93 |
97 |
else {
|
94 |
|
my $cvar = _new_cvar($self, %params, config => $_);
|
|
98 |
$cvar = _new_cvar($self, %params, config => $_);
|
95 |
99 |
$self->add_custom_variables($cvar);
|
96 |
|
$cvar;
|
|
100 |
$cvar->{is_valid} = 1;
|
97 |
101 |
}
|
|
102 |
$cvar->{config} = $_;
|
|
103 |
$cvar;
|
98 |
104 |
}
|
99 |
105 |
@$configs
|
100 |
106 |
);
|
... | ... | |
168 |
174 |
|
169 |
175 |
require SL::DB::CustomVariableConfig;
|
170 |
176 |
|
171 |
|
SL::DB::Manager::CustomVariableConfig->get_all_sorted($params{module} ? (query => [ module => $params{module} ]) : ());
|
|
177 |
my $cache = $::request->cache("::SL::DB::Helper::CustomVariables::object_cache");
|
|
178 |
|
|
179 |
if (!$cache->{all}) {
|
|
180 |
my $configs = SL::DB::Manager::CustomVariableConfig->get_all_sorted;
|
|
181 |
$cache->{all} = $configs;
|
|
182 |
$cache->{module} = { partition_by { $_->module } @$configs };
|
|
183 |
}
|
|
184 |
|
|
185 |
$params{module}
|
|
186 |
? $cache->{modules}{$params{module}}
|
|
187 |
: $cache->{all};
|
172 |
188 |
}
|
173 |
189 |
|
174 |
190 |
sub _overload_by_module {
|
... | ... | |
353 |
369 |
);
|
354 |
370 |
}
|
355 |
371 |
|
|
372 |
|
|
373 |
sub _all_invalids {
|
|
374 |
my ($trans_id, $configs, %params) = @_;
|
|
375 |
|
|
376 |
require SL::DB::CustomVariableValidity;
|
|
377 |
|
|
378 |
# easy 1: no trans_id, all valid by default.
|
|
379 |
return [] unless $trans_id;
|
|
380 |
|
|
381 |
# easy 2: no module in params? no validity
|
|
382 |
return [] unless $params{module};
|
|
383 |
|
|
384 |
my @module_configs = grep { $_->module eq $params{module} } @$configs;
|
|
385 |
|
|
386 |
return [] unless @module_configs;
|
|
387 |
|
|
388 |
# nor find all entries for that and return
|
|
389 |
SL::DB::Manager::CustomVariableValidity->get_all(
|
|
390 |
query => [
|
|
391 |
config_id => [ map { $_->id } @module_configs ],
|
|
392 |
trans_id => $trans_id,
|
|
393 |
]
|
|
394 |
);
|
|
395 |
}
|
|
396 |
|
356 |
397 |
1;
|
357 |
398 |
|
358 |
399 |
__END__
|
CustomVariables: Requestlevel Caching für cvars_by_config
- Configs werden jetzt gecacht.
- is_valid wird en bloc vorberechnet und im Objekt gecacht.