Mojito/Model/Doc/Elasticsearch.pm

filter: Statementstmt 13.6% 12 / 88 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 3 / 8 Podpod 80.0% 4 / 5 totaltotal 15.2% 19 / 125 CC 12 SCAR 27.4
CC
12
Cov
11%
get_docs_for_month
30.0
get_collection_pages
20.0
get_feed_docs
12.0
CRAP 15.4
« Mojito/Page/Git.pm ↑ Summary Mojito.pm »
1 4 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Model::Doc::Elasticsearch;
3 4 $Mojito::Model::Doc::Elasticsearch::VERSION = '0.25';
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 with('Mojito::Role::DB::Elasticsearch');
8  
9 =head1 Methods
10  
11 =head2 get_most_recent_docs
12  
13 =cut
14  
15 0 ▶sub get_most_recent_docs {
Subroutine get_most_recent_docs: not called CC=2 SCAR=17.9
Pod documented
16 0 my ($self) = @_;
17 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
18 0 my $docs = $self->collection->{hits}{hits};
19 0 my @docs = map { $_->{_source} } @{$docs};
20 my @sorted_docs = sort {
21 0 $b->{last_modified} <=> $a->{last_modified}
22 0 } @docs;
23 0 return [@sorted_docs];
24 }
25  
26 =head2 get_feed_docs
27  
28 Get the documents for a particular feed sorted by date in reverse chrono order.
29  
30 =cut
31  
32 0 ▶sub get_feed_docs {
Subroutine get_feed_docs: not called CC=3 SCAR=24.8
Pod documented
33 0 my ($self, $feed) = @_;
34 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
35 0 my $collection = $self->collection;
36 0 my @docs = map { $_->{_source} } @{$collection->{hits}{hits}};
37 0 ▶ my @feed_docs = grep { $_->{feeds} && $_->{feeds} eq $feed } @docs;
Condition0%0/3
$_->{'feeds'} && $_->{'feeds'} eq $feed
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'feeds'} && $_->{'feeds'} eq $feed
$_->{'feeds'} $_->{'feeds'} eq $feed
Truth table0%0/3
A && B
A= $_->{'feeds'}B= $_->{'feeds'} eq $feed
ABresult
0X0
100
111
38 0 @feed_docs = sort { $b->{last_modified} <=> $a->{last_modified} } @feed_docs;
39 0 return \@feed_docs;
40 }
41  
42 =head2 get_collections
43  
44 Get the collections by name sorted by date in reverse chrono order.
45  
46 =cut
47  
48 0 ▶sub get_collections {
Subroutine get_collections: not called CC=2 SCAR=17.9
Pod documented
49 0 my $self = shift;
50
51 0 $self->clear_collection_name;
52 0 $self->clear_collection;
53 0 $self->collection_name('collection');
54 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
55 0 my $collections = $self->collection->{hits}{hits};
56 0 my @collections = map { $_->{_source} } @{$collections};
57 my @sorted_collections = sort {
58 0 $b->{last_modified} <=> $a->{last_modified}
59 0 } @collections;
60  
61 0 return [@sorted_collections];
62 }
63  
64 =head2 get_collection_pages
65  
66 Get the pages belonging to a particular collection.
67 NOTE: We get the list of page ids from the collection collected_page_ids value.
68 Then we find all documents corresponding to those ids.
69  
70 Return an (collection_name, ArrayRef of pages);
71  
72 =cut
73  
74 0 ▶sub get_collection_pages {
Subroutine get_collection_pages: not called CC=4 SCAR=30.0
Pod documented
75 0 my ($self, $collection_id) = @_;
76  
77 0 $self->clear_collection_name;
78 0 $self->clear_collection;
79 0 $self->collection_name('collection');
80 0 my $collection;
81 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $collection = $self->db->get_source("index", $self->db_name, "type", $self->collection_name, "id", $collection_id); 1 } }) 0 0 0
82 eval {
83 0 $collection = $self->db->get_source(
84 index => $self->db_name,
85 type => $self->collection_name,
86 id => $collection_id,
87 0 ); 1;
88 }) {
89 0 warn "WARNING: Collection with id: $collection_id not found";
90 0 return;
91 }
92 0 my $page_ids = $collection->{collected_page_ids};
93 # Change to notes collection
94 0 $self->clear_collection_name;
95 0 $self->clear_collection;
96 0 $self->collection_name('notes');
97 0 my @pages;
98 0 foreach my $id (@{$page_ids}) {
99 0 my $page;
100 0 ▶ unless ( eval {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $page = $self->db->get_source("index", $self->db_name, "type", $self->collection_name, "id", $id); 1 } }) 0 0 0
101 0 $page = $self->db->get_source(
102 index => $self->db_name,
103 type => $self->collection_name,
104 id => $id,
105 0 ); 1;
106 }) {
107 0 warn "WARNING: Collection with id: $id not found";
108 0 next;
109 }
110 0 push @pages, $page;
111 }
112 0 return ($collection->{collection_name}, \@pages);
113 }
114  
115 0 ▶sub get_docs_for_month {
Subroutine get_docs_for_month: not called CC=5 SCAR=34.0
Pod undocumented
116 0 my ($self, $month, $year) = @_;
117  
118 0 my %monthly_data = ();
119 0 my $start_epoch = DateTime->new(
120 year => $year,
121 month => $month,
122 day => 1,
123 hour => 0,
124 minute => 0,
125 second => 0,
126 )->epoch;
127 0 ▶ my $next_month = ($month == 12) ? 1 : $month + 1;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
128 0 ▶ my $year_of_next_month = ($month == 12) ? $year + 1 : $year;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
129 0 my $end_epoch = DateTime->new(
130 year => $year_of_next_month,
131 month => $next_month,
132 day => 1,
133 hour => 0,
134 minute => 0,
135 second => 0,
136 )->epoch;
137 0 my $docs = $self->collection->{hits}{hits};
138 0 my @docs = map { $_->{_source} } @{$docs};
139 0 ▶ @docs = grep { ($_->{last_modified} >= $start_epoch) && ($_->{last_modified} <= $end_epoch) } @docs;
Condition0%0/3
$_->{'last_modified'} >= $start_epoch && $_->{'last_modified'} <= $end_epoch
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'last_modified'} >= $start_epoch && $_->{'last_modified'} <= $end_epoch
$_->{'last_modified'} >= $start_epoch $_->{'last_modified'} <= $end_epoch
Truth table0%0/3
A && B
A= $_->{'last_modified'} >= $start_epochB= $_->{'last_modified'} <= $end_epoch
ABresult
0X0
100
111
140 0 @docs = sort { $b->{last_modified} <=> $a->{last_modified} } @docs;
141 0 foreach my $doc (@docs) {
142 0 my $day = DateTime->from_epoch(epoch => $doc->{last_modified})->day;
143 0 push @{ $monthly_data{$day} },
144 0 { id => $doc->{id}, title => $doc->{title} };
145 }
146 0 return %monthly_data;
147 }
148  
149 4 1;
« Mojito/Page/Git.pm ↑ Summary Mojito.pm »