Skip to content

Commit

Permalink
Merge 303769e into 1b49f5f
Browse files Browse the repository at this point in the history
  • Loading branch information
Pchelolo committed Apr 15, 2019
2 parents 1b49f5f + 303769e commit 6213d68
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 138 deletions.
13 changes: 0 additions & 13 deletions projects/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,5 @@ paths:
- path: sys/mobileapps.js
options: '{{merge({"response_cache_control": options.purged_cache_control},
options.mobileapps)}}'
/mobile_bucket:
x-modules:
- path: sys/multi_content_bucket.js
options:
grace_ttl: '{{default(options.parsoid.grace_ttl, 86400)}}'
delete_probability: '{{default(options.parsoid.delete_probability, 1)}}'
table_name_prefix: mobile
main_content_type:
name: lead
value_type: json
dependent_content_types:
- name: remaining
value_type: json
options: '{{options}}'

17 changes: 2 additions & 15 deletions projects/wmf_enwiki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ paths:
allows us to contact you quickly. Email addresses or URLs
of contact pages work well.
By using this API, you agree to Wikimedia's
By using this API, you agree to Wikimedia's
[Terms of Use](https://wikimediafoundation.org/wiki/Terms_of_Use) and
[Privacy Policy](https://wikimediafoundation.org/wiki/Privacy_policy).
Unless otherwise specified in the endpoint documentation
below, content accessed via this API is licensed under the
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
and [GFDL](https://www.gnu.org/copyleft/fdl.html) licenses,
and you irrevocably agree to release modifications or
additions made through this API under these licenses.
Expand Down Expand Up @@ -221,19 +221,6 @@ paths:
- path: sys/mobileapps.js
options: '{{merge({"response_cache_control": options.purged_cache_control},
options.mobileapps)}}'
/mobile_bucket:
x-modules:
- path: sys/multi_content_bucket.js
options:
grace_ttl: '{{default(options.parsoid.grace_ttl, 86400)}}'
delete_probability: '{{default(options.parsoid.delete_probability, 1)}}'
table_name_prefix: mobile_ng
main_content_type:
name: lead
value_type: json
dependent_content_types:
- name: remaining
value_type: json
/events:
x-modules:
- path: sys/events.js
Expand Down
17 changes: 2 additions & 15 deletions projects/wmf_wikipedia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ paths:
allows us to contact you quickly. Email addresses or URLs
of contact pages work well.
By using this API, you agree to Wikimedia's
By using this API, you agree to Wikimedia's
[Terms of Use](https://wikimediafoundation.org/wiki/Terms_of_Use) and
[Privacy Policy](https://wikimediafoundation.org/wiki/Privacy_policy).
Unless otherwise specified in the endpoint documentation
below, content accessed via this API is licensed under the
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
and [GFDL](https://www.gnu.org/copyleft/fdl.html) licenses,
and you irrevocably agree to release modifications or
additions made through this API under these licenses.
Expand Down Expand Up @@ -242,19 +242,6 @@ paths:
- path: sys/mobileapps.js
options: '{{merge({"response_cache_control": options.purged_cache_control},
options.mobileapps)}}'
/mobile_bucket:
x-modules:
- path: sys/multi_content_bucket.js
options:
grace_ttl: '{{default(options.parsoid.grace_ttl, 86400)}}'
delete_probability: '{{default(options.parsoid.delete_probability, 1)}}'
table_name_prefix: mobile_ng
main_content_type:
name: lead
value_type: json
dependent_content_types:
- name: remaining
value_type: json
/events:
x-modules:
- path: sys/events.js
Expand Down
13 changes: 0 additions & 13 deletions projects/wmf_wikivoyage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,6 @@ paths:
x-modules:
- path: sys/mobileapps.js
options: '{{merge({"response_cache_control": options.purged_cache_control}, options.mobileapps)}}'
/mobile_bucket:
x-modules:
- path: sys/multi_content_bucket.js
options:
grace_ttl: '{{default(options.parsoid.grace_ttl, 86400)}}'
delete_probability: '{{default(options.parsoid.delete_probability, 1)}}'
table_name_prefix: mobile_ng
main_content_type:
name: lead
value_type: json
dependent_content_types:
- name: remaining
value_type: json
/events:
x-modules:
- path: sys/events.js
Expand Down
19 changes: 3 additions & 16 deletions projects/wmf_wiktionary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ paths:
allows us to contact you quickly. Email addresses or URLs
of contact pages work well.
By using this API, you agree to Wikimedia's
By using this API, you agree to Wikimedia's
[Terms of Use](https://wikimediafoundation.org/wiki/Terms_of_Use) and
[Privacy Policy](https://wikimediafoundation.org/wiki/Privacy_policy).
Unless otherwise specified in the endpoint documentation
below, content accessed via this API is licensed under the
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
and [GFDL](https://www.gnu.org/copyleft/fdl.html) licenses,
and you irrevocably agree to release modifications or
additions made through this API under these licenses.
additions made through this API under these licenses.
See https://www.mediawiki.org/wiki/REST_API for background and details.
### Endpoint documentation
Expand Down Expand Up @@ -174,19 +174,6 @@ paths:
- path: sys/mobileapps.js
options: '{{merge({"response_cache_control": options.purged_cache_control},
options.mobileapps)}}'
/mobile_bucket:
x-modules:
- path: sys/multi_content_bucket.js
options:
grace_ttl: '{{default(options.parsoid.grace_ttl, 86400)}}'
delete_probability: '{{default(options.parsoid.delete_probability, 1)}}'
table_name_prefix: mobile_ng
main_content_type:
name: lead
value_type: json
dependent_content_types:
- name: remaining
value_type: json
/events:
x-modules:
- path: sys/events.js
Expand Down
98 changes: 33 additions & 65 deletions sys/mobileapps.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const P = require('bluebird');
const HyperSwitch = require('hyperswitch');
const URI = HyperSwitch.URI;
const mwUtils = require('../lib/mwUtil');

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/mobileapps.yaml`);

const BUCKET_NAME = 'mobile-sections';

class MobileApps {
constructor(options) {
this._options = options;
Expand All @@ -18,56 +19,29 @@ class MobileApps {
}

const rp = req.params;
const fetchPaths = {
lead: [rp.domain, 'sys', 'mobile_bucket', 'lead', rp.title],
remaining: [rp.domain, 'sys', 'mobile_bucket', 'remaining', rp.title]
};
if (rp.revision) {
fetchPaths.lead.push(rp.revision);
fetchPaths.remaining.push(rp.revision);
}
return P.join(
hyper.get({
uri: new URI(fetchPaths.lead)
}),
hyper.get({
uri: new URI(fetchPaths.remaining)
})
).spread((lead, remaining) => ({
status: 200,
headers: lead.headers,
body: {
lead: lead.body,
remaining: remaining.body
return hyper.get({
uri: new URI([rp.domain, 'sys', 'key_value', BUCKET_NAME, rp.title])
})
.then((res) => {
res.body = JSON.parse(res.body.toString('utf8'));
if (!rp.revision ||
`${mwUtils.parseETag(res.headers.etag).rev}` === `${rp.revision}`) {
return res;
}
}))
return this._fetchFromMCS(hyper, req);
})
.catch({ status: 404 }, () => this._fetchFromMCSAndStore(hyper, req));
}

getPart(part, hyper, req) {
const rp = req.params;
const fetchAndReturnPart = () => this._fetchFromMCSAndStore(hyper, req)
return this.getSections(hyper, req)
.then((res) => {
return {
status: 200,
status: res.status,
headers: res.headers,
body: res.body[part]
};
});

if (mwUtils.isNoCacheRequest(req)) {
return fetchAndReturnPart();
}

const fetchPath = [rp.domain, 'sys', 'mobile_bucket', part, rp.title];
if (rp.revision) {
fetchPath.push(rp.revision);
}

return hyper.get({
uri: new URI(fetchPath)
})
.catch({ status: 404 }, fetchAndReturnPart);
}

_purgeURIs(hyper, req, revision, purgeLatest) {
Expand Down Expand Up @@ -101,7 +75,7 @@ class MobileApps {
});
}

_fetchFromMCSAndStore(hyper, req) {
_fetchFromMCS(hyper, req) {
const rp = req.params;
let serviceURI = `${this._options.host}/${rp.domain}/v1/page/mobile-sections`;
serviceURI += `/${encodeURIComponent(rp.title)}`;
Expand All @@ -114,33 +88,29 @@ class MobileApps {
headers: {
'accept-language': req.headers['accept-language']
}
})
});
}

_fetchFromMCSAndStore(hyper, req) {
const rp = req.params;

return this._fetchFromMCS(hyper, req)
.then((res) => {
if (mwUtils.isNoStoreRequest(req)) {
return res;
}
return hyper.put({
uri: new URI([rp.domain, 'sys', 'mobile_bucket', 'all', rp.title,
res.body.lead.revision,
mwUtils.parseETag(res.headers.etag).tid]),
body: {
lead: {
headers: res.headers,
body: res.body.lead
},
remaining: {
headers: res.headers,
body: res.body.remaining
}
}
uri: new URI([rp.domain, 'sys', 'key_value', BUCKET_NAME, rp.title]),
headers: {
'content-type': 'application/octet-stream',
'x-store-etag': res.headers.etag,
'x-store-content-language': res.headers['content-language'],
'x-store-content-type': res.headers['content-type'],
'x-store-vary': res.headers.vary
},
body: Buffer.from(JSON.stringify(res.body))
})
.tap(() =>
this._purgeURIs(hyper, req, res.body.lead.revision, true))
// TODO: This means we never store older revisions for mobile!
// Need to add the fallback when mobile-references get implemented!
.catch({ status: 412 }, () =>
// 412 means that it's an older revision
this._purgeURIs(hyper, req, res.body.lead.revision, false))
.tap(() => this._purgeURIs(hyper, req, res.body.lead.revision, true))
.thenReturn(res);
});
}
Expand All @@ -157,9 +127,7 @@ module.exports = (options) => {
getSectionsRemaining: mobileApps.getPart.bind(mobileApps, 'remaining')
},
resources: [
{
uri: '/{domain}/sys/mobile_bucket/'
}
{ uri: `/{domain}/sys/key_value/${BUCKET_NAME}` }
]
};
};
2 changes: 1 addition & 1 deletion test/features/specification/monitoring.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const parallel = require('mocha.parallel');
const parallel = describe;//require('mocha.parallel');
const preq = require('preq');
const assert = require('../../utils/assert.js');
const Server = require('../../utils/server.js');
Expand Down

0 comments on commit 6213d68

Please sign in to comment.