From e77f46a6c82be6763bcdb2b34de233b8e36a1e34 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Tue, 12 Jun 2018 13:11:09 +0300 Subject: [PATCH] Include `pagelanguage` into the title_revision table. For language variants support it's not enough to look whether the domain language supports multiple variants, since on every wiki each page can actually have it's own lang, and since LanguageConverter is enabled universally, the individual pages could be transformed even on wikis where we generically don't support variants. Thus, we need to include `pagelanguage` property into the title_revision table in order to be able to check, whether to try the transformtion, or just to skip it. Also will be useful to do Varnish cache splitting more intelegently. Bug: https://phabricator.wikimedia.org/T190689 Change-Id: I92052e3f7980d005f1df8810f3641e92bdc9fc9b --- sys/page_revisions.js | 23 +++++++++++++++++++++-- v1/content.yaml | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sys/page_revisions.js b/sys/page_revisions.js index 012e53bf4..cc901b4dc 100644 --- a/sys/page_revisions.js +++ b/sys/page_revisions.js @@ -43,7 +43,7 @@ class PRS { getTableSchema() { return { table: tableName, - version: 1, + version: 2, attributes: { title: 'string', page_id: 'int', @@ -61,7 +61,8 @@ class PRS { timestamp: 'timestamp', comment: 'string', redirect: 'boolean', - page_deleted: 'int' + page_deleted: 'int', + page_language: 'string' }, index: [ { attribute: 'title', type: 'hash' }, @@ -360,6 +361,23 @@ class PRS { } return revisionRequest .then((res) => { + // TODO: temprorary code to ensure all revision responces + // have the pagelanguage property set. + if (res.body.items.length && !res.body.items[0].page_language) { + if (mwUtil.isNoCacheRequest(req)) { + hyper.logger.log('error/pagelanguage', { + msg: 'Failed to fetch pagelanguage', + page_title: rp.title, + page_revision: rp.revision + }); + } else { + req.headers = req.headers || {}; + req.headers['cache-control'] = 'no-cache'; + return this.getTitleRevision(hyper, req); + } + } + // End of temporary code + // Check if the revision has any restrictions this._checkRevReturn(res.body.items.length && res.body.items[0]); @@ -584,6 +602,7 @@ class PRS { comment: restrictions.indexOf('commenthidden') < 0 ? apiRev.comment : null, tags: apiRev.tags, restrictions, + page_language: dataResp.pagelanguage, // Get the redirect property, it's inclusion means true // FIXME: Figure out redirect strategy: https://phabricator.wikimedia.org/T87393 redirect: dataResp.redirect !== undefined diff --git a/v1/content.yaml b/v1/content.yaml index ff51431e9..018a1abf3 100644 --- a/v1/content.yaml +++ b/v1/content.yaml @@ -113,6 +113,7 @@ paths: rev: /\d+/ tid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ comment: /.*/ + page_language: 'en' /html/{title}: x-route-filters: @@ -868,6 +869,8 @@ definitions: format: date-time redirect: type: boolean + page_language: + type: string revisionIdentifier: description: Unique revision identifier