Skip to content

Commit

Permalink
Implemented indexing all files as a job at the first login. This chan…
Browse files Browse the repository at this point in the history
…ge helps to close #9.
  • Loading branch information
stoshiya committed Sep 4, 2014
1 parent 23dd85c commit 9df6949
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ app.use(session({ secret: 'secret', resave: true, saveUninitialized: true, cooki
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next) {
// run indexing for all entries at the first login.
if (req.isAuthenticated() && typeof req.session.callbackURL !=='undefined') {
routes.entities(req.session.passport.user.id, req.session.passport.user.accessToken, '0', function(err) {
if (err) {
console.error(err);
} else {
console.log('finished to create indexing for all entities.');
}
});
}
next();
});


var auth = function(req, res, next) {
Expand Down
18 changes: 18 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ function search(req, res) {
});
}

function entities(userId, token, id, callback) {
async.waterfall([
function (callback) {
invoker.folder(token, id, callback);
},
function (result, callback) {
async.eachSeries(result.item_collection.entries, function(entry, callback) {
if (entry.type === 'folder') {
entities(userId, token, entry.id, callback);
} else {
indexing(userId, token, entry.id, callback);
}
}, callback);
}
], callback);
}

exports.index = index;
exports.folders = folders;
exports.files = files;
Expand All @@ -218,3 +235,4 @@ exports.zip = zip;
exports.pdf = pdf;
exports.createIndex = createIndex;
exports.search = search;
exports.entities = entities;

0 comments on commit 9df6949

Please sign in to comment.