Skip to content

Commit

Permalink
fix(list): allow searching with owner set to alias
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Mar 17, 2016
1 parent 88b6220 commit d5bd9c8
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/actions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,49 @@ module.exports = function postProcessFile(opts) {
const { owner, filter, public: isPublic, offset, limit, order, criteria } = opts;
const strFilter = is.string(filter) ? filter : fsort.filter(filter || {});

// choose which set to use
let filesIndex;
if (isPublic && owner) {
filesIndex = `${FILES_INDEX}:${owner}:pub`;
} else if (owner) {
filesIndex = `${FILES_INDEX}:${owner}`;
} else if (isPublic) {
filesIndex = FILES_INDEX_PUBLIC;
} else {
filesIndex = FILES_INDEX;
}
return Promise
.bind(this)
.then(() => {
if (!owner) {
return [];
}

return this.postHook.call(this, 'files:info:pre', owner);
})
.spread(username => {
// choose which set to use
let filesIndex;
if (isPublic && username) {
filesIndex = `${FILES_INDEX}:${username}:pub`;
} else if (username) {
filesIndex = `${FILES_INDEX}:${username}`;
} else if (isPublic) {
filesIndex = FILES_INDEX_PUBLIC;
} else {
filesIndex = FILES_INDEX;
}

return redis
.fsort(filesIndex, `${FILES_DATA}:*`, criteria, order, strFilter, offset, limit)
return redis.fsort(filesIndex, `${FILES_DATA}:*`, criteria, order, strFilter, offset, limit);
})
.then(filenames => {
const length = +filenames.pop();
if (length === 0 || filenames.length === 0) {
return [
filenames || [],
[],
return {
filenames,
props: [],
length,
];
};
}

const pipeline = redis.pipeline();
filenames.forEach(filename => {
pipeline.hgetall(`${FILES_DATA}:${filename}`);
});

return Promise.join(
filenames,
pipeline.exec(),
length
);
return Promise.props({ filenames, props: pipeline.exec(), length });
})
.spread((filenames, props, length) => {
.then(data => {
const { filenames, props, length } = data;
const files = filenames.map(function remapData(filename, idx) {
const meta = props[idx][1];

Expand Down

0 comments on commit d5bd9c8

Please sign in to comment.