line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
2157
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
157
|
|
2
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
189
|
|
3
|
|
|
|
|
|
|
package Search::GIN::Driver; |
4
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
5
|
4
|
|
|
4
|
|
16
|
use Moose::Role; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
28
|
|
6
|
4
|
|
|
4
|
|
16356
|
use Data::Stream::Bulk::Util qw(bulk nil cat unique); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
69
|
|
7
|
4
|
|
|
4
|
|
1290
|
use namespace::autoclean; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
28
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw( |
10
|
|
|
|
|
|
|
insert_entry |
11
|
|
|
|
|
|
|
remove_ids |
12
|
|
|
|
|
|
|
fetch_entry |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub fetch_entry_streams { |
16
|
14
|
|
|
14
|
0
|
32
|
my ( $self, %args ) = @_; |
17
|
14
|
|
|
|
|
17
|
map { $self->fetch_entry($_) } @{ $args{values} }; |
|
15
|
|
|
|
|
218
|
|
|
14
|
|
|
|
|
31
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub fetch_entries { |
21
|
14
|
|
|
14
|
0
|
45
|
my ( $self, %args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
14
|
|
100
|
|
|
70
|
my $method = "fetch_entries_" . ( $args{method} || "any" ); |
24
|
|
|
|
|
|
|
|
25
|
14
|
|
|
|
|
67
|
$self->$method(%args); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub fetch_entries_any { |
29
|
4
|
|
|
4
|
0
|
12
|
my ( $self, @args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
16
|
my @streams = $self->fetch_entry_streams(@args); |
32
|
|
|
|
|
|
|
|
33
|
4
|
50
|
|
|
|
282
|
return nil unless @streams; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
24
|
my $res = cat(splice @streams); # splice disposes of @streams ASAP, keeping memory utilization down |
36
|
|
|
|
|
|
|
|
37
|
4
|
50
|
|
|
|
324
|
if ( $res->loaded ) { |
38
|
|
|
|
|
|
|
# if all results are already ready, we can uniqify them to avoid |
39
|
|
|
|
|
|
|
# duplicate calls to ->consistent |
40
|
4
|
|
|
|
|
45
|
return unique($res); |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
0
|
return $res; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub fetch_entries_all { |
47
|
10
|
|
|
10
|
0
|
19
|
my ( $self, @args ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
10
|
|
|
|
|
28
|
my @streams = $self->fetch_entry_streams(@args); |
50
|
|
|
|
|
|
|
|
51
|
10
|
100
|
|
|
|
628
|
return nil unless @streams; |
52
|
9
|
100
|
|
|
|
62
|
return $streams[0] if @streams == 1; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
3
|
foreach my $stream ( @streams ) { |
55
|
2
|
50
|
|
|
|
11
|
return cat(splice @streams) unless $stream->loaded; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# if we made it to here then we have a > 1 list of fully realized streams |
59
|
|
|
|
|
|
|
# we can compute the intersection of the IDs to avoid unnecessary calls to |
60
|
|
|
|
|
|
|
# ->consistent |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# If all streams are known to be sorted this method could be overridden to |
63
|
|
|
|
|
|
|
# use merge sorting |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
6
|
my $last = shift @streams; |
66
|
1
|
|
|
|
|
2
|
my $n = scalar @streams; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# compute intersection |
69
|
1
|
|
|
|
|
2
|
my %seen; |
70
|
1
|
|
|
|
|
4
|
foreach my $stream ( splice @streams ) { |
71
|
1
|
|
|
|
|
5
|
++$seen{$_} for $stream->all; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
4
|
|
1395
|
no warnings 'uninitialized'; # == with undef |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
413
|
|
75
|
1
|
|
|
|
|
255
|
return bulk( grep { $seen{$_} == $n } $last->all ); |
|
2
|
|
|
|
|
194
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |