Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/335370 )
Change subject: Trending takes optional period parameter ...................................................................... Trending takes optional period parameter This allows us to pull out only pages that have been edited within a certain number of hours Bug: T156680 Change-Id: Ied5ca3e7253d414129692bc3c2b96cc81e2fa99c --- M lib/filter-pages.js M routes/trending-v1.js M test/features/lib/filter-pages.js 3 files changed, 21 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/trending-edits refs/changes/70/335370/1 diff --git a/lib/filter-pages.js b/lib/filter-pages.js index 6fc8023..c0f2ad1 100644 --- a/lib/filter-pages.js +++ b/lib/filter-pages.js @@ -19,8 +19,9 @@ function filterPages(candidates, options) { options = options || {}; const minEdits = options.min_edits || DEFAULT_MIN_EDITS; + const since = options.since; return candidates.filter((candidate) => { - return candidate.edits > minEdits; + return candidate.edits > minEdits && (!options.since || new Date(candidate.from) >= new Date(since)); }); } diff --git a/routes/trending-v1.js b/routes/trending-v1.js index 1b239fd..4293f4e 100644 --- a/routes/trending-v1.js +++ b/routes/trending-v1.js @@ -46,9 +46,13 @@ * GET /feed/trending-edits * Gets the body of a given page. */ -router.get('/trending-edits', function(req, res) { +router.get('/trending-edits/:period?', function(req, res) { const domain = req.params.domain; - const conf = app.conf; + const period = req.params.period || 24; + const now = new Date(); + const conf = Object.assign({ + since: new Date(now.getTime() - (period * 24 * 60 * 1000)).toUTCString() + }, app.conf); if (/^en\.wikipedia\./.test(domain)) { var date = new Date(); diff --git a/test/features/lib/filter-pages.js b/test/features/lib/filter-pages.js index 47ca10a..47492b9 100644 --- a/test/features/lib/filter-pages.js +++ b/test/features/lib/filter-pages.js @@ -16,5 +16,18 @@ var pages = filterPages( input ); assert.ok( pages.length === 0, 'Filtering occurs' ); }); + + it('Period can be used in filtering', function() { + var input = [ + { edits: 20, from: '2017-01-31T16:00:00+00:00' }, + { edits: 21, from: '2017-01-31T18:00:00+00:00' }, + { title: 'a', edits: 20, from: '2017-01-31T19:00:00+00:00' }, + { title: 'b', edits: 20, from: '2017-01-31T21:00:00+00:00' } + ]; + var pages = filterPages( input, { min_edits: 5, since: '2017-01-31T19:00:00+00:00' } ); + assert.ok( pages.length === 2, 'Only pages that have occurred since 7pm are kept' ); + assert.ok( pages[0].title === 'a', 'Only pages that have occurred since 7pm are kept' ); + assert.ok( pages[1].title === 'b', 'Only pages that have occurred since 7pm are kept' ); + }); }); -- To view, visit https://gerrit.wikimedia.org/r/335370 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ied5ca3e7253d414129692bc3c2b96cc81e2fa99c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/trending-edits Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits