Sitic has uploaded a new change for review. https://gerrit.wikimedia.org/r/225675
Change subject: Cleanup code ...................................................................... Cleanup code Minor changes, renames some functions and moves code around. Change-Id: I9b3ad2da890c23ed784664c84a7be7e30da881f6 --- M backend/celery/api.py M backend/celery/tasks.py M frontend/src/components/watchlist/edit_oneline.directive.html M frontend/src/components/watchlist/edit_twolines.directive.html M frontend/src/components/watchlist/entry.directive.html M frontend/src/components/watchlist/page.directive.js M frontend/src/components/watchlist/user.directive.js M frontend/src/components/watchlist/watchlist.controller.js M frontend/src/components/watchlist/watchlist.html M scripts/restart_celery.sh 10 files changed, 44 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/tools/crosswatch refs/changes/75/225675/1 diff --git a/backend/celery/api.py b/backend/celery/api.py index 16c7617..feb5134 100644 --- a/backend/celery/api.py +++ b/backend/celery/api.py @@ -16,7 +16,6 @@ def __init__(self, host="https://en.wikipedia.org", path="/w/api.php", access_token=None, redis_channel=None): self.api_url = host + path - self.wikis = {} user_agent = "crosswatch (https://tools.wmflabs.org/crosswatch;" +\ "crosswa...@tools.wmflabs.org) python-requests/" +\ @@ -56,7 +55,7 @@ time = now + delta return time.strftime("%Y%m%d%H%M%S") - def handle_response(self, response): + def _handle_response(self, response): if 'error' in response: logger.error(response['error']) @@ -79,7 +78,7 @@ response = requests.get(self.api_url, params=params, auth=self.auth, headers=self.headers).json() - self.handle_response(response) + self._handle_response(response) return response def query_gen(self, params): @@ -105,7 +104,7 @@ response = requests.post(self.api_url, params=params, data=payload, auth=self.auth, headers=self.headers) - self.handle_response(json.loads(response.text)) + self._handle_response(json.loads(response.text)) def get_token(self, type='csrf'): params = {'action': "query", @@ -115,7 +114,7 @@ token = r['query']['tokens'][type + 'token'] return token - def get_username(self): + def username(self): params = { 'action': "query", 'meta': "userinfo", @@ -124,7 +123,22 @@ username = response['query']['userinfo']['name'] return username - def get_wikis(self, use_cache=True): + def diff(self, pageid, old_revid, new_revid): + params = { + 'action': "query", + 'prop': "revisions", + 'rvstartid': old_revid, + 'rvendid': old_revid, + 'rvdiffto': new_revid, + 'pageids': pageid, + 'formatversion': 2 + } + + response = self.query(params) + diff = response['query']['pages'][0]['revisions'][0]['diff']['body'] + return diff + + def wikis(self, use_cache=True): key = config.redis_prefix + 'cached_wikis' wikis = self.redis.get(key) if use_cache and wikis: @@ -132,29 +146,32 @@ else: # Cache miss, do api request and fill cache wikis = self._get_wikis() - self.redis.setex(key, 86400, json.dumps(wikis)) # 1 day exp. + self.redis.setex(key, 172800, json.dumps(wikis)) # 2 days exp. return wikis def _get_wikis(self): params = {'action': "sitematrix"} data = self.query(params) + + wikis = {} for key, val in data['sitematrix'].items(): if key == 'count': continue if 'code' in val: for site in val['site']: - self._parse_sitematrix(site, val['code'], val['name']) + wiki = self._create_wiki(site, val['code'], val['name']) + wikis[site['dbname']] = wiki else: for site in val: - self._parse_sitematrix(site, '', '') + wiki = self._create_wiki(site, '', '') + wikis[site['dbname']] = wiki + return wikis - return self.wikis - - def _parse_sitematrix(self, site, lang, langname): + def _create_wiki(self, site, langcode, langname): wiki = { - 'lang': lang, + 'lang': langcode, 'langname': langname, 'url': site['url'].replace("http://", "https://"), 'dbname': site['dbname'], @@ -166,5 +183,4 @@ inactive_wikis = ['closed', 'private', 'fishbowl'] if any([key in site for key in inactive_wikis]): wiki['closed'] = True - - self.wikis[site['dbname']] = wiki + return wiki diff --git a/backend/celery/tasks.py b/backend/celery/tasks.py index c9e91c2..196dad5 100644 --- a/backend/celery/tasks.py +++ b/backend/celery/tasks.py @@ -31,8 +31,8 @@ """ mw = MediaWiki(access_token=obj['access_token']) - username = mw.get_username() - wikis = mw.get_wikis() + username = mw.username() + wikis = mw.wikis() # Use cache of known projects to bypass sometimes blocking mysql check preload_projects = obj.pop('projects', []) @@ -208,7 +208,7 @@ Mark echo notifications as read """ mw = MediaWiki(access_token=obj['access_token']) - wikis = mw.get_wikis() + wikis = mw.wikis() params = {'action': "echomarkread"} for project, notifications in obj['notifications'].iteritems(): @@ -227,18 +227,8 @@ mw = MediaWiki(host=obj['projecturl'], access_token=obj['access_token'], redis_channel=obj['redis_channel']) - params = { - 'action': "query", - 'prop': "revisions", - 'rvstartid': obj['old_revid'], - 'rvendid': obj['old_revid'], - 'rvdiffto': obj['revid'], - 'pageids': obj['pageid'], - 'formatversion': 2 - } - response = mw.query(params) - diff = response['query']['pages'][0]['revisions'][0]['diff']['body'] + diff = mw.diff(obj['pageid'], obj['old_revid'], obj['revid']) mw.publish({ 'msgtype': 'diff_response', 'request_id': obj['request_id'], diff --git a/frontend/src/components/watchlist/edit_oneline.directive.html b/frontend/src/components/watchlist/edit_oneline.directive.html index b1419b7..6393d39 100644 --- a/frontend/src/components/watchlist/edit_oneline.directive.html +++ b/frontend/src/components/watchlist/edit_oneline.directive.html @@ -3,7 +3,7 @@ ><span class="botedit" ng-if="::event.bot" translate="BOTEDIT_FLAG"></span> <a stop-event dir="ltr" href="{{::event.projecturl}}/w/index.php?oldid={{::event.old_revid}}&diff={{::event.revid}}" ng-class="::event.titlestyle" target="_blank">{{::event.title}}</a> -<span ng-if="event.clicked"> +<span ng-if="event.showDiff"> (<a stop-event href="{{::event.projecturl}}/w/index.php?title={{::event.title | urlEncode}}&action=history" target="_blank" translate="HISTORY"></a>) </span> <span am-time-ago="event.timestamp"></span> diff --git a/frontend/src/components/watchlist/edit_twolines.directive.html b/frontend/src/components/watchlist/edit_twolines.directive.html index bc0074a..392add9 100644 --- a/frontend/src/components/watchlist/edit_twolines.directive.html +++ b/frontend/src/components/watchlist/edit_twolines.directive.html @@ -3,7 +3,7 @@ ><span class="botedit" ng-if="::event.bot" translate="BOTEDIT_FLAG" >dir="auto"></span> <a stop-event href="{{::event.projecturl}}/w/index.php?oldid={{::event.old_revid}}&diff={{::event.revid}}" ng-class="::event.titlestyle" target="_blank">{{::event.title}}</a> -<span ng-if="event.clicked"> +<span ng-if="event.showDiff"> (<a stop-event href="{{::event.projecturl}}/w/index.php?title={{::event.title | urlEncode}}&action=history" target="_blank" translate="HISTORY"></a>) </span>  <span dir="auto" ng-class="::event.bytestyle">({{::event.bytes}})</span> diff --git a/frontend/src/components/watchlist/entry.directive.html b/frontend/src/components/watchlist/entry.directive.html index 9adbcbb..237f11b 100644 --- a/frontend/src/components/watchlist/entry.directive.html +++ b/frontend/src/components/watchlist/entry.directive.html @@ -38,7 +38,7 @@ </div> </div> -<table ng-if="event.clicked && event.diff" class="diff diff-contentalign-left"> +<table ng-if="event.showDiff && event.diff" class="diff diff-contentalign-left"> <colgroup><col class="diff-marker"> <col class="diff-content"> <col class="diff-marker"> diff --git a/frontend/src/components/watchlist/page.directive.js b/frontend/src/components/watchlist/page.directive.js index eb3cc37..30e962c 100644 --- a/frontend/src/components/watchlist/page.directive.js +++ b/frontend/src/components/watchlist/page.directive.js @@ -7,7 +7,7 @@ link: link, scope: true, template: '<a stop-event href="{{::event.projecturl}}/wiki/{{::title | urlEncode}}" target="_blank">{{::title}}</a> ' + - '<span ng-if="event.clicked">' + + '<span ng-if="event.showDiff">' + '(<a stop-event href="{{::event.projecturl}}/w/index.php?title={{::title | urlEncode}}&action=history" target="_blank" translate="HISTORY"></a>)' + '</span> ', restrict: 'E' diff --git a/frontend/src/components/watchlist/user.directive.js b/frontend/src/components/watchlist/user.directive.js index 590c245..dd29a8e 100644 --- a/frontend/src/components/watchlist/user.directive.js +++ b/frontend/src/components/watchlist/user.directive.js @@ -7,7 +7,7 @@ link: link, scope: true, template: '<a stop-event dir="auto" href="{{::event.projecturl}}/wiki/User:{{::user | urlEncode}}" target="_blank">{{::user}}</a> ' + - '<span dir="auto" ng-if="event.clicked">' + + '<span dir="auto" ng-if="event.showDiff">' + '(<a stop-event href="{{::event.projecturl}}/wiki/Special:Contributions/{{::user | urlEncode}}" target="_blank" translate="CONTRIBS"></a>)' + '</span> ', restrict: 'E' diff --git a/frontend/src/components/watchlist/watchlist.controller.js b/frontend/src/components/watchlist/watchlist.controller.js index 81c79c3..f7d57ce 100644 --- a/frontend/src/components/watchlist/watchlist.controller.js +++ b/frontend/src/components/watchlist/watchlist.controller.js @@ -14,6 +14,8 @@ }; vm.clicked = function (event) { + event.showDiff = !event.showDiff; + if ((event.type === 'edit') && !event.diff) { dataService.getDiff(event).then(function (diff) { event.diff = diff; diff --git a/frontend/src/components/watchlist/watchlist.html b/frontend/src/components/watchlist/watchlist.html index 5c420be..23dad7c 100644 --- a/frontend/src/components/watchlist/watchlist.html +++ b/frontend/src/components/watchlist/watchlist.html @@ -27,7 +27,7 @@ <md-list-item layout="row" class="watchlist" ng-class="[{'watchlist-list-item-oneline': ctrl.config.oneline}, ctrl.config.projectColors[event.project]]" ng-repeat="event in ctrl.watchlist.active track by event.id"> - <watchlist-entry ng-click="event.clicked = !event.clicked; ctrl.clicked(event)" md-ink-ripple></watchlist-entry> + <watchlist-entry ng-click="ctrl.clicked(event)" md-ink-ripple></watchlist-entry> <md-divider></md-divider> </md-list-item> </md-list> diff --git a/scripts/restart_celery.sh b/scripts/restart_celery.sh index 0a1b6ff..21773f3 100755 --- a/scripts/restart_celery.sh +++ b/scripts/restart_celery.sh @@ -8,6 +8,6 @@ done for i in $(seq 1 ${num}); do - jstart -N celery${i} -once -continuous -l h_vmem=3G -l release=trusty ./celery.grid.sh $i + jstart -N celery${i} -once -continuous -l h_vmem=2G -l release=trusty ./celery.grid.sh $i sleep 10 done -- To view, visit https://gerrit.wikimedia.org/r/225675 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b3ad2da890c23ed784664c84a7be7e30da881f6 Gerrit-PatchSet: 1 Gerrit-Project: labs/tools/crosswatch Gerrit-Branch: master Gerrit-Owner: Sitic <jan.leb...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits