lib/Serge/DB/Cached.pm

filter: Statementstmt 64.8% 214 / 330 Branchbran 35.4% 66 / 186 Conditioncond 24.3% 10 / 41 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 86.6% 39 / 45 Podpod 0.0% 0 / 30 totaltotal 50.0% 329 / 657 SCAR 72.4
CC
108
Cov
52%
find_best_translation
169.0
preload_cache_for_job
50.7
get_source_string
30.0
CRAP 1392.7
« lib/Serge/Engine/Plugin/parse_csv.pm ↑ Summary lib/Serge/Engine/Plugin/parse_pot.pm »
1 package Serge::DB::Cached;
2 2 ▶use parent Serge::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Digest::MD5 qw(md5);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Serge::Util qw(generate_key generate_hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $DEBUG = $ENV{CI} ne ''; # use debug mode from under CI environment to ensure better coverage
14  
15 2 ▶our $CACHING_STRATEGY = lc($ENV{SERGE_DB_CACHING_STRATEGY}) || "db";
Condition50%1/2
lc $ENV{'SERGE_DB_CACHING_STRATEGY'} || 'db'
l!l
02
MC/DC0%0/1
lc $ENV{'SERGE_DB_CACHING_STRATEGY'} || 'db'
lc $ENV{'SERGE_DB_CACHING_STRATEGY'}
Truth table50%1/2
A
A= lc $ENV{'SERGE_DB_CACHING_STRATEGY'}
Aresult
11
00
16 2 ▶if ($CACHING_STRATEGY !~ m/^(db|namespace|file|string)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Serge::DB::Cached::CACHING_STRATEGY =~ /^(db|namespace|file|string)$/) 0 2 2
17 0 die "Invalid SERGE_DB_CACHING_STRATEGY value: [$ENV{SERGE_DB_CACHING_STRATEGY}]. ".
18 "Valid values are: 'db' (default), 'namespace', 'file' and 'string'.\n";
19 }
20  
21 sub open {
22 6 ▶ my ($self, $source, $username, $password) = @_;
Subroutine open: called CC=6 SCAR=22.4
Pod undocumented
23  
24 # if parameters din't change, just stay connected
25 # to the previously opened database
26  
27 6 ▶ if (exists $self->{dsn} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"dsn"} and $self->{"dsn"}{"source"} eq $source and $self->{"dsn"}{"username"} eq $username and $self->{"dsn"}{"password"} eq $password) 0 6 6
Condition33%3/9
exists $self->{"dsn"} and $self->{"dsn"}{"source"} eq $source and $self->{"dsn"}{"username"} eq $username and $self->{"dsn"}{"password"} eq $password
!ll&&!rl&&r
600
exists $self->{"dsn"} and $self->{"dsn"}{"source"} eq $source and $self->{"dsn"}{"username"} eq $username
!ll&&!rl&&r
600
exists $self->{"dsn"} and $self->{"dsn"}{"source"} eq $source
!ll&&!rl&&r
060
MC/DC0%0/4
exists $self->{"dsn"} and $self->{"dsn"}{"source"} eq $source and $self->{"dsn"}{"username"} eq $username and $self->{"dsn"}{"password"} eq $password
exists $self->{"dsn"} $self->{"dsn"}{"source"} eq $source $self->{"dsn"}{"username"} eq $username $self->{"dsn"}{"password"} eq $password
Truth table20%1/5
A and B and C and D
A= exists $self->{"dsn"}B= $self->{"dsn"}{"source"} eq $sourceC= $self->{"dsn"}{"username"} eq $usernameD= $self->{"dsn"}{"password"} eq $password
ABCDresult
0XXX0
10XX0
110X0
11100
11111
28 ($self->{dsn}->{source} eq $source) and
29 ($self->{dsn}->{username} eq $username) and
30 ($self->{dsn}->{password} eq $password)) {
31 0 print "Reusing previously opened database connection\n";
32 0 return $self->{dbh};
33 }
34  
35 6 ▶ $self->close if $self->{dbh};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbh"} 0 6 6
36  
37 $self->{dsn} = {
38 6 source => $source,
39 username => $username,
40 password => $password
41 };
42  
43 6 $self->{dsn_hash} = generate_hash($source, $username, $password);
44  
45 $self->{cache} = {
46 6 job => {},
47 properties => {},
48 translations => {}
49 };
50  
51 6 return $self->SUPER::open($source, $username, $password);
52 }
53  
54 sub close {
55 6 ▶ my ($self) = @_;
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
56 6 $self->{cache} = {};
57 6 delete $self->{dsn};
58 6 delete $self->{dsn_hash};
59 6 return $self->SUPER::close;
60 }
61  
62 sub _copy_props {
63 164 ▶ my ($self, $h_old, $h_new) = @_;
Subroutine _copy_props: called CC=3 SCAR=11.0
64  
65 164 my $result = undef;
66 164 foreach (keys %$h_new) {
67 320 ▶ $result = 1 if $h_new->{$_} ne $h_old->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $h_new->{$_} ne $h_old->{$_} 0 320 320
68 320 $h_old->{$_} = $h_new->{$_};
69 }
70 164 return $result;
71 }
72  
73 #
74 # strings
75 #
76  
77 sub get_string_id {
78 108 ▶ my ($self, $string, $context, $nocreate) = @_;
Subroutine get_string_id: called CC=4 SCAR=14.3
Pod undocumented
79  
80 108 my $key = 'string_id:'.generate_key($string, $context);
81  
82 108 ▶ if (exists $self->{cache}->{job}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"job"}{$key}) 68 40 108
83 68 my $id = $self->{cache}->{job}->{$key};
84 68 ▶ return $id if $id or $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $id or $nocreate 68 0 68
Condition33%1/3
$id or $nocreate
l!l&&r!l&&!r
6800
MC/DC0%0/2
$id or $nocreate
$id $nocreate
Truth table33%1/3
A or B
A= $idB= $nocreate
ABresult
1X1
011
000
85 }
86  
87 40 return $self->{cache}->{job}->{$key} = $self->SUPER::get_string_id($string, $context, $nocreate);
88 }
89  
90 sub update_string_props {
91 0 ▶ my ($self, $string_id, $props) = @_;
Subroutine update_string_props: not called CC=3 SCAR=24.8
Pod undocumented
92  
93 0 my $key = "string:$string_id";
94  
95 0 my $h = $self->{cache}->{job}->{$key};
96 0 ▶ $h = $self->{cache}->{job}->{$key} = $self->SUPER::get_string_props($string_id) unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 0 0 0
97  
98 0 ▶ return $self->SUPER::update_string_props($string_id, $props) if $self->_copy_props($h, $props);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_copy_props($h, $props) 0 0 0
99 }
100  
101 sub get_string_props {
102 81 ▶ my ($self, $string_id) = @_;
Subroutine get_string_props: called CC=2 SCAR=6.9
Pod undocumented
103  
104 81 my $key = "string:$string_id";
105  
106 81 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 41 40 81
107  
108 40 return $self->{cache}->{job}->{$key} = $self->SUPER::get_string_props($string_id);
109 }
110  
111 #
112 # items
113 #
114  
115 sub get_item_id {
116 108 ▶ my ($self, $file_id, $string_id, $hint, $nocreate) = @_;
Subroutine get_item_id: called CC=7 SCAR=20.6
Pod undocumented
117  
118 108 my $key = "item_id:$file_id:$string_id";
119  
120 108 ▶ if (exists $self->{cache}->{job}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"job"}{$key}) 54 54 108
121 54 my $id = $self->{cache}->{job}->{$key};
122 54 ▶ return $id if $id or $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $id or $nocreate 54 0 54
Condition33%1/3
$id or $nocreate
l!l&&r!l&&!r
5400
MC/DC0%0/2
$id or $nocreate
$id $nocreate
Truth table33%1/3
A or B
A= $idB= $nocreate
ABresult
1X1
011
000
123 }
124  
125 # now check if the file was preloaded in the cache,
126 # and if it was (which means that all known item_id should
127 # also be there in the cache, then return undef if $nocreate flag is set
128  
129 54 my $file_key = "file:$file_id";
130  
131 54 ▶ if (exists $self->{cache}->{job}->{$file_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"job"}{$file_key}) 54 0 54
132 54 ▶ return undef if $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $nocreate 0 54 54
133 }
134  
135 54 ▶ $hint = undef if $hint eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $hint eq "" 0 54 54
136  
137 54 return $self->{cache}->{job}->{$key} = $self->SUPER::get_item_id($file_id, $string_id, $hint, $nocreate);
138 }
139  
140 sub update_item_props {
141 0 ▶ my ($self, $item_id, $props) = @_;
Subroutine update_item_props: not called CC=3 SCAR=24.8
Pod undocumented
142  
143 0 my $key = "item:$item_id";
144  
145 0 my $h = $self->{cache}->{job}->{$key};
146 0 ▶ $h = $self->{cache}->{job}->{$key} = $self->SUPER::get_item_props($item_id) unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 0 0 0
147  
148 0 ▶ return $self->SUPER::update_item_props($item_id, $props) if $self->_copy_props($h, $props);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_copy_props($h, $props) 0 0 0
149 }
150  
151 sub get_item_props {
152 135 ▶ my ($self, $item_id) = @_;
Subroutine get_item_props: called CC=2 SCAR=6.9
Pod undocumented
153  
154 135 my $key = "item:$item_id";
155  
156 135 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 81 54 135
157  
158 54 return $self->{cache}->{job}->{$key} = $self->SUPER::get_item_props($item_id);
159 }
160  
161 #
162 # files
163 #
164  
165 sub get_file_id {
166 24 ▶ my ($self, $namespace, $job, $path, $nocreate) = @_;
Subroutine get_file_id: called CC=4 SCAR=14.3
Pod undocumented
167  
168 24 my $key = 'file_id:'.md5(encode_utf8(join("\001", ($namespace, $job, $path))));
169  
170 24 ▶ if (exists $self->{cache}->{job}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"job"}{$key}) 16 8 24
171 16 my $id = $self->{cache}->{job}->{$key};
172 16 ▶ return $id if $id or $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $id or $nocreate 16 0 16
Condition33%1/3
$id or $nocreate
l!l&&r!l&&!r
1600
MC/DC0%0/2
$id or $nocreate
$id $nocreate
Truth table33%1/3
A or B
A= $idB= $nocreate
ABresult
1X1
011
000
173 }
174  
175 8 return $self->{cache}->{job}->{$key} = $self->SUPER::get_file_id($namespace, $job, $path, $nocreate);
176 }
177  
178 sub update_file_props {
179 0 ▶ my ($self, $file_id, $props) = @_;
Subroutine update_file_props: not called CC=3 SCAR=24.8
Pod undocumented
180  
181 0 my $key = "file:$file_id";
182  
183 0 my $h = $self->{cache}->{job}->{$key};
184 0 ▶ $h = $self->{cache}->{job}->{$key} = $self->SUPER::get_file_props($file_id) unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 0 0 0
185  
186 0 ▶ return $self->SUPER::update_file_props($file_id, $props) if $self->_copy_props($h, $props);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_copy_props($h, $props) 0 0 0
187 }
188  
189 sub get_file_props {
190 35 ▶ my ($self, $file_id) = @_;
Subroutine get_file_props: called CC=2 SCAR=6.9
Pod undocumented
191  
192 35 my $key = "file:$file_id";
193  
194 35 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 27 8 35
195  
196 8 return $self->{cache}->{job}->{$key} = $self->SUPER::get_file_props($file_id);
197 }
198  
199 #
200 # translations
201 #
202  
203 sub get_translation_id {
204 108 ▶ my ($self, $item_id, $lang, $string, $fuzzy, $comment, $merge, $nocreate) = @_;
Subroutine get_translation_id: called CC=4 SCAR=14.0
Pod undocumented
205  
206 108 my $key = "translation_id:$item_id:$lang";
207  
208 108 ▶ if (exists $self->{cache}->{job}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"job"}{$key}) 54 54 108
209 54 my $id = $self->{cache}->{job}->{$key};
210 54 ▶ return $id if $id or $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $id or $nocreate 54 0 54
Condition66%2/3
$id or $nocreate
l!l&&r!l&&!r
26280
MC/DC0%0/2
$id or $nocreate
$id $nocreate
Truth table66%2/3
A or B
A= $idB= $nocreate
ABresult
1X1
011
000
211 }
212  
213 54 return $self->{cache}->{job}->{$key} = $self->SUPER::get_translation_id($item_id, $lang, $string, $fuzzy, $comment, $merge, $nocreate);
214 }
215  
216 sub update_translation_props {
217 52 ▶ my ($self, $translation_id, $props) = @_;
Subroutine update_translation_props: called CC=3 SCAR=11.0
Pod undocumented
218  
219 52 my $key = "translation:$translation_id";
220  
221 52 my $h = $self->{cache}->{job}->{$key};
222 52 ▶ $h = $self->{cache}->{job}->{$key} = $self->SUPER::get_translation_props($translation_id) unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 26 26 52
223  
224 52 ▶ return $self->SUPER::update_translation_props($translation_id, $props) if $self->_copy_props($h, $props);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_copy_props($h, $props) 0 52 52
225 }
226  
227 sub get_translation_props {
228 0 ▶ my ($self, $translation_id) = @_;
Subroutine get_translation_props: not called CC=2 SCAR=17.9
Pod undocumented
229  
230 0 my $key = "translation:$translation_id";
231  
232 0 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 0 0 0
233  
234 0 return $self->{cache}->{job}->{$key} = $self->SUPER::get_translation_props($translation_id);
235 }
236  
237 sub set_translation {
238 52 ▶ my ($self, $item_id, $lang, $string, $fuzzy, $comment, $merge) = @_;
Subroutine set_translation: called CC=8 SCAR=21.4
Pod undocumented
239  
240 52 ▶ $string = undef if $string eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $string eq "" 0 52 52
241 52 ▶ $comment = undef if $comment eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $comment eq "" 52 0 52
242 52 ▶ $fuzzy = $fuzzy ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fuzzy ? : 0 52 52
243 52 ▶ $merge = $merge ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$merge ? : 0 52 52
244  
245 52 my $id = $self->get_translation_id($item_id, $lang, $string, $fuzzy, $comment, $merge); # create if necessary
246  
247 # if translations cache was preloaded, update it as well
248 52 my $cache = $self->{cache}->{translations}->{$lang};
249 52 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 27 25 52
250 27 my $i = $self->get_item_props($item_id);
251 27 ▶ if ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 27 0 27
252 27 my $s = $self->get_string_props($i->{string_id});
253 27 my $f = $self->get_file_props($i->{file_id});
254 27 my $skey = generate_key($s->{string});
255  
256 27 ▶ $cache->{$skey} = {} unless exists $cache->{$skey};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cache->{$skey} 0 27 27
257 $cache->{$skey}->{$item_id} = {
258 namespace => $f->{namespace},
259 path => $f->{path},
260 context => $s->{context},
261 27 orphaned => undef,
262 string => $string,
263 fuzzy => $fuzzy,
264 comment => $comment,
265 };
266 }
267 }
268  
269 52 $self->update_translation_props($id, {
270 string => $string,
271 fuzzy => $fuzzy,
272 comment => $comment,
273 merge => $merge,
274 });
275 }
276  
277 #
278 # properties
279 #
280  
281 sub get_property_id {
282 228 ▶ my ($self, $property, $value, $nocreate) = @_;
Subroutine get_property_id: called CC=4 SCAR=20.4
Pod undocumented
283  
284 228 my $key = "property_id:$property";
285  
286 228 ▶ if (exists $self->{cache}->{properties}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}{"properties"}{$key}) 0 228 228
287 0 my $id = $self->{cache}->{properties}->{$key};
288 0 ▶ return $id if $id or $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if $id or $nocreate 0 0 0
Condition0%0/3
$id or $nocreate
l!l&&r!l&&!r
000
MC/DC0%0/2
$id or $nocreate
$id $nocreate
Truth table0%0/3
A or B
A= $idB= $nocreate
ABresult
1X1
011
000
289 }
290  
291 228 return $self->{cache}->{$key} = $self->SUPER::get_property_id($property, $value, $nocreate);
292 }
293  
294 sub update_property_props {
295 112 ▶ my ($self, $property_id, $props) = @_;
Subroutine update_property_props: called CC=3 SCAR=11.3
Pod undocumented
296  
297 112 my $key = "property:$property_id";
298  
299 112 my $h = $self->{cache}->{properties}->{$key};
300 112 ▶ $h = $self->{cache}->{properties}->{$key} = $self->SUPER::get_property_props($property_id) unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 112 0 112
301  
302 112 ▶ return $self->SUPER::update_property_props($property_id, $props) if $self->_copy_props($h, $props);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_copy_props($h, $props) 0 112 112
303 }
304  
305 sub get_property_props {
306 8 ▶ my ($self, $property_id) = @_;
Subroutine get_property_props: called CC=2 SCAR=7.6
Pod undocumented
307  
308 8 my $key = "property:$property_id";
309  
310 8 ▶ return $self->{cache}->{properties}->{$key} if exists $self->{cache}->{properties}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"properties"}{$key} 8 0 8
311 0 return $self->{cache}->{properties}->{$key} = $self->SUPER::get_property_props($property_id);
312 }
313  
314 sub get_property {
315 62 ▶ my ($self, $property) = @_;
Subroutine get_property: called CC=3 SCAR=11.0
Pod undocumented
316  
317 62 my $id = $self->get_property_id($property, undef, 1); # do not create
318  
319 62 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 8 54 62
320 8 my $props = $self->get_property_props($id);
321 8 ▶ return $props->{value} if $props;
Branch: 1 branch
BranchTrueFalseTotal
if $props 8 0 8
322 }
323 54 return $self->SUPER::get_property($property);
324 }
325  
326 sub set_property {
327 112 ▶ my ($self, $property, $value) = @_;
Subroutine set_property: called CC=1 SCAR=0.0
Pod undocumented
328  
329 112 my $id = $self->get_property_id($property, $value); # create if necessary
330  
331 112 return $self->update_property_props($id, {'value' => $value});
332 }
333  
334 #
335 # Other
336 #
337  
338 sub get_all_items_for_file {
339 8 ▶ my ($self, $file_id) = @_;
Subroutine get_all_items_for_file: called CC=2 SCAR=7.0
Pod undocumented
340  
341 8 my $key = "all_items:$file_id";
342  
343 8 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 0 8 8
344 8 return $self->{cache}->{job}->{$key} = $self->SUPER::get_all_items_for_file($file_id);
345 }
346  
347 sub get_file_completeness_ratio {
348 0 ▶ my ($self, $file_id, $lang, $total) = @_;
Subroutine get_file_completeness_ratio: not called CC=2 SCAR=17.9
Pod undocumented
349  
350 0 my $key = "completeness:$file_id:$lang:$total";
351  
352 0 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 0 0 0
353 0 return $self->{cache}->{job}->{$key} = $self->SUPER::get_file_completeness_ratio($file_id, $lang, $total);
354 }
355  
356 sub get_all_files_for_job {
357 6 ▶ my ($self, $namespace, $job) = @_;
Subroutine get_all_files_for_job: called CC=2 SCAR=7.0
Pod undocumented
358  
359 6 my $key = "all_files:$namespace:$job";
360  
361 6 ▶ return $self->{cache}->{job}->{$key} if exists $self->{cache}->{job}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"cache"}{"job"}{$key} 0 6 6
362 6 return $self->{cache}->{job}->{$key} = $self->SUPER::get_all_files_for_job($namespace, $job);
363 }
364  
365 sub get_translation {
366 56 ▶ my ($self, $item_id, $lang, $allow_skip) = @_;
Subroutine get_translation: called CC=4 SCAR=23.3
Pod undocumented
367  
368 56 my $translation_id = $self->get_translation_id($item_id, $lang, undef, undef, undef, undef, 1); # do not create
369  
370 56 ▶ if ($translation_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($translation_id) 0 56 56
371 0 my $i = $self->get_item_props($item_id);
372 0 my $s = $self->get_string_props($i->{string_id});
373  
374 0 my $props = $self->get_translation_props($translation_id);
375 0 ▶ return if $s->{skip} and !$allow_skip;
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"skip"} and not $allow_skip 0 0 0
Condition0%0/3
$s->{"skip"} and not $allow_skip
!ll&&!rl&&r
000
MC/DC0%0/2
$s->{"skip"} and not $allow_skip
$s->{"skip"} not $allow_skip
Truth table0%0/3
A and not(B)
A= $s->{"skip"}B= not $allow_skip
ABresult
0X0
100
111
376 0 return ($props->{string}, $props->{fuzzy}, $props->{comment}, $props->{merge}, $s->{skip});
377 }
378 }
379  
380 sub preload_full_cache_items {
381 5 ▶ my ($self, $lang_cache, $lang, $extra_params) = @_;
Subroutine preload_full_cache_items: called CC=11 SCAR=30.2
Pod undocumented
382  
383  
384 5 my $extra_query;
385 5 ▶ if ($CACHING_STRATEGY eq 'db') {
Branch: 4 branches
BranchTrueFalseTotal
if ($Serge::DB::Cached::CACHING_STRATEGY eq 'db') { } 5 0 5
elsif ($Serge::DB::Cached::CACHING_STRATEGY eq 'namespace') { } 0 0 0
elsif ($Serge::DB::Cached::CACHING_STRATEGY eq 'file') { } 0 0 0
elsif ($Serge::DB::Cached::CACHING_STRATEGY eq 'string') { } 0 0 0
386 5 $extra_query = '';
387 } elsif ($CACHING_STRATEGY eq 'namespace') {
388 0 $extra_query = <<__END__;
389 AND s.id IN (
390 SELECT DISTINCT s.id
391  
392 FROM strings s
393  
394 JOIN items i ON i.string_id = s.id
395 JOIN files f ON i.file_id = f.id
396  
397 WHERE s.skip = 0
398 AND f.namespace = ?
399 )
400 __END__
« lib/Serge/Engine/Plugin/parse_csv.pm ↑ Summary lib/Serge/Engine/Plugin/parse_pot.pm »