Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace property and secondary index #178

Merged
merged 4 commits into from
Feb 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions mods/page_revisions.js
Expand Up @@ -43,6 +43,7 @@ PRS.prototype.getTableSchema = function () {
rev: 'int', // MediaWiki oldid
latest_rev: 'int', // Latest MediaWiki revision
tid: 'timeuuid',
namespace: 'int', // the namespace ID of the page
// revision deletion or suppression, can be:
// - sha1hidden, commenthidden, texthidden
restrictions: 'set<string>',
Expand Down Expand Up @@ -71,6 +72,12 @@ PRS.prototype.getTableSchema = function () {
{ attribute: 'tid', type: 'range', order: 'desc' },
{ attribute: 'title', type: 'range', order: 'asc' },
{ attribute: 'restrictions', type: 'proj' }
],
by_ns: [
{ attribute: 'namespace', type: 'hash' },
{ attribute: 'title', type: 'range', order: 'asc' },
{ attribute: 'rev', type: 'range', order: 'desc' },
{ attribute: 'tid', type: 'range', order: 'desc' }
]
}
};
Expand All @@ -81,7 +88,7 @@ PRS.prototype.getTableSchema = function () {
* for restrictions, and if there are any, raises an error
*
* @param res Object the result as returned from storage
* @return Object the same object
* @return true
* @throws rbUtil.httpError if access to the revision should be denied
*/
PRS.prototype._checkRevReturn = function(res) {
Expand All @@ -101,7 +108,7 @@ PRS.prototype._checkRevReturn = function(res) {
}
});
}
return Promise.resolve(res);
return true;
}

// /page/
Expand Down Expand Up @@ -178,6 +185,7 @@ PRS.prototype.fetchAndStoreMWRevision = function (restbase, req) {
title: dataResp.title,
rev: parseInt(apiRev.revid),
tid: tid,
namespace: parseInt(dataResp.ns),
user_id: apiRev.userid,
user_text: apiRev.user,
comment: apiRev.comment,
Expand All @@ -191,15 +199,15 @@ PRS.prototype.fetchAndStoreMWRevision = function (restbase, req) {
// revision, forbid its retrieval, cf.
// https://phabricator.wikimedia.org/T76165#1030962
if (restrictions && restrictions.length > 0) {
return Promise.reject(new rbUtil.HTTPError({
throw new rbUtil.HTTPError({
status: 403,
body: {
type: 'access_denied#revision',
title: 'Access to resource denied',
description: 'Access is restricted for revision ' + apiRev.revid,
restrictions: restrictions
}
}));
});
}
// no restrictions, continue
rp.revision = apiRev.revid + '';
Expand Down Expand Up @@ -340,7 +348,14 @@ PRS.prototype.getRevision = function(restbase, req) {
limit: 1
}
})
.then(self._checkRevReturn)
.then(function(res) {
// check the return
self._checkRevReturn(res);
// and get the revision info for the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

// page now that we have the title
rp.title = res.body.items[0].title;
return self.getTitleRevision(restbase, req);
})
.catch(function(e) {
if (e.status !== 404) {
throw e;
Expand Down