Mobrovac has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/391986 )
Change subject: Fix eslint warnings ...................................................................... Fix eslint warnings Bug: T151395 Change-Id: I718800cfc99a682986a4fb4faa0a4bbe1368a27a --- M lib/EventProcessor.js M lib/EventSource.js M lib/score-pages.js M routes/trending-v1.js 4 files changed, 50 insertions(+), 62 deletions(-) Approvals: Mobrovac: Verified; Looks good to me, approved jenkins-bot: Verified diff --git a/lib/EventProcessor.js b/lib/EventProcessor.js index 9bd734a..cc30725 100644 --- a/lib/EventProcessor.js +++ b/lib/EventProcessor.js @@ -1,14 +1,12 @@ "use strict"; -/* eslint-disable */ const EventEmitter = require('events').EventEmitter; /** * Remove page with id from the store - * * @ignore * @param {Map} pages - * @param {Number} id + * @param {number} id */ function remove(pages, id) { pages.delete(id); @@ -17,8 +15,8 @@ /** * @ignore * @param {Object} page description - * @param {Object} with keys edits and min_editors defining what trending looks like - * @return {Boolean} whether the page is trending + * @param {Object} definition with keys edits and min_editors defining what trending looks like + * @return {boolean} whether the page is trending */ function isTrending(page, definition) { return page.edits >= definition.min_edits && @@ -27,9 +25,8 @@ /** * Guesses whether an edit was a revert of an earlier edit - * * @param {Object} edit - * @return {Boolean} whether the given edit was a revert + * @return {boolean} whether the given edit was a revert */ function isRevert(edit) { if (!edit.comment) { @@ -44,7 +41,6 @@ class EventProcessor extends EventEmitter { /** * Creates the EventProcessor object and prepares it for purging and processing actions - * * @param {Object} purgeStrategy options for purging. * @param {Object} [logger] to log warnings and errors to */ @@ -65,10 +61,9 @@ /** * Return page with id from the store - * * @ignore - * @param {Number} id of page - * @param {Object} page + * @param {number} id of page + * @return {Object} page */ getPage(id) { return this.pages.get(id); @@ -76,20 +71,21 @@ /** * Process data structure representing edit - * * @param {Object} edit - * @return {Boolean} whether the given edit event has been processed + * @return {boolean} whether the given edit event has been processed */ process(edit) { - let contributors, page, bytesChanged; + let bytesChanged; + let contributors; + let page; const id = edit.page_id; - const ts = new Date(edit.rev_timestamp); const performer = edit.performer; const isAnon = edit.performer.user_id === undefined; - const username = performer.user_text; - const topic = edit.meta.topic; - const pages = this.pages; const isBot = performer.user_is_bot; + const pages = this.pages; + const topic = edit.meta.topic; + const ts = new Date(edit.rev_timestamp); + const username = performer.user_text; // ignore the event if it isn't related to enwiki if (!/^en\.wikipedia\./.test(edit.meta.domain)) { @@ -111,7 +107,7 @@ page = pages.get(id); } else { page = { - id: id, + id, isNew: edit.rev_parent_id === undefined, edits: 0, from: ts, @@ -164,10 +160,9 @@ /** * Purge any pages that do not meet the required criteria - * * @ignore * @param {Date} date to purge against - * @return {Boolean} if fallback purge strategy using max_pages was invoked + * @return {boolean} if fallback purge strategy using max_pages was invoked */ purge(date) { const options = this.purgeOptions; @@ -179,8 +174,9 @@ const size = pages.size; pages.forEach((page) => { - let timePassed = (date - page.from) / 60000; - let speed = timePassed > 0 ? page.edits / timePassed : page.edits; + const timePassed = (date - page.from) / 60000; + const speed = timePassed > 0 ? page.edits / timePassed : page.edits; + if (page.updated < maxInactivityDate || page.from < maxAgeDate) { remove(pages, page.id); } else if (speed < options.min_speed) { @@ -198,15 +194,17 @@ // Only do this if we have to if (size > options.max_pages) { - this.getPages().sort(function(a, b) { + this.getPages().sort((a, b) => { return a.from < b.from ? -1 : 1; - }).slice(0, size - options.max_pages).forEach(function(page) { + }).slice(0, size - options.max_pages).forEach((page) => { remove(pages, page.id); }); if (this.logger) { this.logger.log('warning/event', () => ({ msg: 'max_page warning', - event: 'max_pages was exceeded. This should not happen and may result in unexpected behaviour. Please update your purge_strategy.' + event: `max_pages was exceeded. + This should not happen and may result in unexpected behaviour. + Please update your purge_strategy.` })); } } diff --git a/lib/EventSource.js b/lib/EventSource.js index 34f9f33..8ab8c06 100644 --- a/lib/EventSource.js +++ b/lib/EventSource.js @@ -1,6 +1,5 @@ "use strict"; -/* eslint-disable */ const kafka = require('node-rdkafka'); const EventEmitter = require('events').EventEmitter; const os = require('os'); @@ -16,7 +15,6 @@ * Defines how often to push the commit to the commit queue. * Maps from the topic name to the skip number. If topic name is * not present no skipping would be happening. - * * @type {Object} */ const COMMIT_PUSH_SKIP = { @@ -25,29 +23,27 @@ /** * Checks whether all the required options are provided. - * * @param {Object} options - the options object * @throws {Error} Throws an Error if the supplied options are invalid. * @return {Object} returns the options back */ function checkOptions(options) { function checkOption(opts, name) { - var val = opts[name]; + const val = opts[name]; if (val === undefined || val === '' || val === null) { throw new Error(`${name} option not set`); } } - ['consume_dc', 'purge_strategy', 'broker_list'].forEach((name) => checkOption(options, name)); + ['consume_dc', 'purge_strategy', 'broker_list'].forEach(name => checkOption(options, name)); ['max_age', 'max_inactivity', 'max_pages', 'min_speed'] - .forEach((name) => checkOption(options.purge_strategy, name)); + .forEach(name => checkOption(options.purge_strategy, name)); return options; } /** * Creates the consumer group ID stable across worker/service restarts. - * * @param {number} workerId the ID of the current worker * @return {string} the consumer group ID */ @@ -70,7 +66,6 @@ class EventSource extends EventEmitter { /** * Creates the EventSource object, subscribes it to Kafka and begins consumption. - * * @param {Object} options * @param {Array} options.consume_dc which datacenters to consume from * @param {number} options.trending_period how long to delay the offset commit @@ -107,8 +102,8 @@ }); } this.emit('edit', msg); - } catch (e) { - this.emit('error', e); + } catch (err) { + this.emit('error', err); } }); }); @@ -127,7 +122,6 @@ * Returns an array of topic names to consume the `mediawiki.revision-create`, * `mediawiki.page-move` and `mediawiki.page-delete` events from * based on the list of datacenter names. - * * @return {Array} List of topics to consume. * @private */ diff --git a/lib/score-pages.js b/lib/score-pages.js index a5891ee..09d9521 100644 --- a/lib/score-pages.js +++ b/lib/score-pages.js @@ -1,21 +1,20 @@ "use strict"; -/* eslint-disable */ -var scorer = require('wikipedia-edits-scorer'); +const scorer = require('wikipedia-edits-scorer'); /** * Score and sort pages * @param {Date} date * @param {Array} pages - * @param {Number} [halflife] greater than 0, which causes scores to decay over time. + * @param {number} [halflife] greater than 0, which causes scores to decay over time. * Will default to 1.5 if none given. * @return {Array} */ function scoreAndSortPages(date, pages, halflife) { halflife = halflife || 1.5; - pages.forEach(function(candidate) { - var contrs = candidate.contributors; + pages.forEach((candidate) => { + const contrs = candidate.contributors; candidate.score = scorer.calculateScore( date, { @@ -30,7 +29,7 @@ halflife ); }); - return pages.sort(function(p1, p2) { + return pages.sort((p1, p2) => { return p1.score > p2.score ? -1 : 1; }); } diff --git a/routes/trending-v1.js b/routes/trending-v1.js index aec72a6..01bbe82 100644 --- a/routes/trending-v1.js +++ b/routes/trending-v1.js @@ -1,41 +1,37 @@ 'use strict'; -/* eslint-disable */ -var BBPromise = require('bluebird'); -var preq = require('preq'); -var domino = require('domino'); -var sUtil = require('../lib/util'); -var apiUtil = require('../lib/api-util'); -var filterPages = require('../lib/filter-pages'); -var scorePages = require('../lib/score-pages'); + +const sUtil = require('../lib/util'); +const filterPages = require('../lib/filter-pages'); +const scorePages = require('../lib/score-pages'); // shortcut -var HTTPError = sUtil.HTTPError; +const HTTPError = sUtil.HTTPError; /** * The main router object */ -var router = sUtil.router(); +const router = sUtil.router(); /** * The main application object reported when this module is require()d */ -var app; +let app; /** /**************************** * TRENDING ENDPOINTS * ****************************/ -var ERROR_UNAVAILABLE = 'Trending is currently not available on this wiki.'; +const ERROR_UNAVAILABLE = 'Trending is currently not available on this wiki.'; function getRbPageSummaryUrl(domain, title) { const request = app.restbase_tpl.expand({ request: { params: { - domain: domain, - path: 'page/summary/' + encodeURIComponent(title) }, + domain, + path: `page/summary/${encodeURIComponent(title)}` }, } }); return request.uri; @@ -45,7 +41,7 @@ * GET /feed/debug-trending-edits * Debugging tools for private usage that expose the contents of the processor */ -router.get('/debug-trending-edits/:id?/:halflife?', function(req, res) { +router.get('/debug-trending-edits/:id?/:halflife?', (req, res) => { const processor = app.processor; if (req.params.id) { const page = processor.getPage(parseInt(req.params.id, 10)); @@ -75,7 +71,7 @@ * GET /feed/trending-edits * Gets the body of a given page. */ -router.get('/trending-edits/:period?', function(req, res) { +router.get('/trending-edits/:period?', (req, res) => { const domain = req.params.domain; const period = req.params.period ? parseInt(req.params.period, 10) : 24; const date = new Date(); @@ -95,8 +91,9 @@ const data = { timestamp: date, // show the 20 scored top pages being edited - pages: scorePages(date, filterPages(app.processor.getPages(), conf), period).slice(0, conf.max_results) - .map(function(page) { + pages: scorePages(date, filterPages(app.processor.getPages(), conf), period) + .slice(0, conf.max_results) + .map((page) => { return { totalEdits: page.edits, editors: page.contributors.total, @@ -128,7 +125,7 @@ return { path: '/feed', api_version: 1, - router: router + router }; }; -- To view, visit https://gerrit.wikimedia.org/r/391986 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I718800cfc99a682986a4fb4faa0a4bbe1368a27a Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/services/trending-edits Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: Ppchelko <ppche...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits