33require ( 'core-js/shim' ) ;
44
55var P = require ( 'bluebird' ) ;
6+ var Template = require ( 'swagger-router' ) . Template ;
67
78var makeFileStore = require ( './filestore' ) ;
89var makeSQLiteStore = require ( './sqlitestore' ) ;
@@ -21,6 +22,9 @@ process.on('SIGUSR2', function() {
2122var preq = require ( 'preq' ) ;
2223var PromiseStream = require ( './PromiseStream' ) ;
2324
25+ // the request template used for fetching each individual article
26+ var articleReqTpl ;
27+
2428function getArticles ( options , res ) {
2529 if ( ! res || res . next === 'finished' ) {
2630 // nothing more to do.
@@ -92,24 +96,12 @@ function dumpArticle (options, title, oldid) {
9296 if ( options . verbose ) {
9397 console . log ( 'Dumping' , title , oldid ) ;
9498 }
95- var url = options . host + '/' + options . prefix
96- + '/v1/page/html/' + encodeURIComponent ( title ) + '/' + oldid ;
97- return preq . get ( {
98- uri : url ,
99- headers : {
100- 'user-agent' : options . userAgent ,
101- 'accept-encoding' : 'gzip'
102- } ,
103- retries : 5 ,
104- timeout : 60000 ,
105- // Request a Buffer by default, don't decode to a String. This
106- // saves CPU cycles, but also a lot of memory as large strings are
107- // stored in the old space of the JS heap while Buffers are stored
108- // outside the JS heap.
109- encoding : null
110- } )
99+ return preq . get ( articleReqTpl . expand ( {
100+ request : {
101+ params : Object . assign ( { title : title , oldid : oldid } , options )
102+ }
103+ } ) )
111104 . then ( function ( res ) {
112- //console.log('done', title);
113105 if ( options . store ) {
114106 return options . store . saveArticle ( res . body , title , oldid ) ;
115107 }
@@ -220,6 +212,23 @@ function makeDump (options) {
220212 storeSetup = makeSQLiteStore ( options ) ;
221213 }
222214
215+ // set up the article request template once on start-up
216+ articleReqTpl = new Template ( {
217+ method : 'get' ,
218+ uri : options . url ,
219+ headers : {
220+ 'user-agent' : options . userAgent ,
221+ 'accept-encoding' : 'gzip'
222+ } ,
223+ retries : 5 ,
224+ timeout : 60000 ,
225+ // Request a Buffer by default, don't decode to a String. This
226+ // saves CPU cycles, but also a lot of memory as large strings are
227+ // stored in the old space of the JS heap while Buffers are stored
228+ // outside the JS heap.
229+ encoding : null
230+ } ) ;
231+
223232 return storeSetup
224233 . then ( function ( store ) {
225234 options . store = store ;
0 commit comments