1 |
commit: 35b9a8c3d05650d4023e7b61ded134314f1f498d |
2 |
Author: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
3 |
AuthorDate: Fri Jan 6 06:03:38 2012 +0000 |
4 |
Commit: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
5 |
CommitDate: Fri Jan 6 06:03:38 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git;a=commit;h=35b9a8c3 |
7 |
|
8 |
[scripts] optimise package query, fix end-point to _search, add debug options in the WWW layer |
9 |
|
10 |
--- |
11 |
scripts/lib/metacpan.pm | 19 ++++++++++++++--- |
12 |
scripts/package_log.pl | 48 +++++++++++++++++++++++++++++----------------- |
13 |
2 files changed, 45 insertions(+), 22 deletions(-) |
14 |
|
15 |
diff --git a/scripts/lib/metacpan.pm b/scripts/lib/metacpan.pm |
16 |
index 58ce0f2..702a2a9 100644 |
17 |
--- a/scripts/lib/metacpan.pm |
18 |
+++ b/scripts/lib/metacpan.pm |
19 |
@@ -20,11 +20,22 @@ sub mcpan { |
20 |
root_dir => File::Spec->catdir( File::Spec->tmpdir, 'gentoo-metacpan-cache' ), |
21 |
); |
22 |
require WWW::Mechanize::Cached; |
23 |
- my $mech = WWW::Mechanize::Cached->new( |
24 |
- cache => $cache, |
25 |
- timeout => 20000, |
26 |
+ my $mech; |
27 |
+ |
28 |
+ if ( defined $ENV{WWW_MECH_NOCACHE} ) { |
29 |
+ $mech = LWP::UserAgent->new(); |
30 |
+ } else { |
31 |
+ $mech = WWW::Mechanize::Cached->new( |
32 |
+ cache => $cache, |
33 |
+ timeout => 20000, |
34 |
autocheck => 1, |
35 |
- ); |
36 |
+ ); |
37 |
+ } |
38 |
+ if ( defined $ENV{WWW_MECH_DEBUG} ) { |
39 |
+ $mech->add_handler("request_send", sub { warn shift->dump ; return }); |
40 |
+ $mech->add_handler("response_done", sub { warn shift->dump ; return }); |
41 |
+ |
42 |
+ } |
43 |
require HTTP::Tiny::Mech; |
44 |
my $tinymech = HTTP::Tiny::Mech->new( mechua => $mech ); |
45 |
require MetaCPAN::API; |
46 |
|
47 |
diff --git a/scripts/package_log.pl b/scripts/package_log.pl |
48 |
index 70547b3..a6bc9fb 100755 |
49 |
--- a/scripts/package_log.pl |
50 |
+++ b/scripts/package_log.pl |
51 |
@@ -49,34 +49,45 @@ my $singleflags; |
52 |
|
53 |
if ( $flags->{help} or $singleflags->{h} ) { print help(); exit 0; } |
54 |
|
55 |
-my $oldest_date = '2011-09-01T00:00:00.000Z'; |
56 |
-my $newest_date = '2012-01-01T00:00:00.000Z'; |
57 |
+my $oldest_date = '2011-10-01T00:00:00.000Z'; |
58 |
+my $newest_date = '2012-02-01T00:00:00.000Z'; |
59 |
|
60 |
my $search = {}; |
61 |
|
62 |
-$search->{query} = { |
63 |
- terms => { |
64 |
- distribution => [ @ARGV, ], |
65 |
- minimum_match => 1, |
66 |
- }, |
67 |
-}; |
68 |
+my $and = []; |
69 |
|
70 |
if ( not $flags->{all} ) { |
71 |
- $search->{filter} = { |
72 |
- range => { |
73 |
- date => { |
74 |
- from => $oldest_date, |
75 |
- to => $newest_date, |
76 |
- }, |
77 |
- }, |
78 |
- }; |
79 |
+ push @{$and}, { |
80 |
+ range => { |
81 |
+ date => { |
82 |
+ from => $oldest_date, |
83 |
+ to => $newest_date, |
84 |
+ } |
85 |
+ } |
86 |
+ }; |
87 |
} |
88 |
+ |
89 |
+push @{$and} , { |
90 |
+ term => { |
91 |
+ 'distribution' => @ARGV, |
92 |
+# minimum_match => 1, |
93 |
+ } |
94 |
+}; |
95 |
+ |
96 |
+$search->{query} = { |
97 |
+ constant_score => { |
98 |
+ filter => { |
99 |
+ and => $and, |
100 |
+ } |
101 |
+ } |
102 |
+}; |
103 |
+ |
104 |
$search->{sort} = [ |
105 |
|
106 |
# { 'author' => 'asc', }, |
107 |
{ 'date' => 'desc', }, |
108 |
]; |
109 |
-$search->{size} = 1024; |
110 |
+$search->{size} = 10; |
111 |
|
112 |
$search->{fields} = [qw( author name date distribution version )]; |
113 |
|
114 |
@@ -84,9 +95,10 @@ if ( $flags->{deps} ) { |
115 |
push @{ $search->{fields} }, '_source.dependency'; |
116 |
} |
117 |
|
118 |
+ |
119 |
_log( ['initialized: fetching search results'] ); |
120 |
|
121 |
-my $results = mcpan->post( 'release', $search ); |
122 |
+my $results = mcpan->post( 'release/_search', $search ); |
123 |
|
124 |
_log( [ 'fetched %s results', scalar @{ $results->{hits}->{hits} } ] ); |