diff --git a/common/session.js b/common/session.js index fec1f09cf..259b34577 100644 --- a/common/session.js +++ b/common/session.js @@ -19,11 +19,23 @@ var connect = require('connect'); var RedisStore = require('connect-redis')(connect); var config = require('../config'); -var session = connect.session({ - key: 'AuthSession', - secret: config.sessionSecret, - store: new RedisStore(config.redis), - cookie: { path: '/', httpOnly: true, maxAge: 3600000 * 24 * 30 }, -}); +var session; +var key = 'AuthSession'; +var cookie = { path: '/', httpOnly: true, maxAge: 3600000 * 24 * 30 }; + +if (config.debug) { + session = connect.cookieSession({ + secret: config.sessionSecret, + key: key, + cookie: cookie + }); +} else { + session = connect.session({ + key: key, + secret: config.sessionSecret, + store: new RedisStore(config.redis), + cookie: cookie, + }); +} module.exports = session; diff --git a/proxy/module.js b/proxy/module.js index 26fffa194..4fd3be42f 100644 --- a/proxy/module.js +++ b/proxy/module.js @@ -15,6 +15,7 @@ */ var utility = require('utility'); +var eventproxy = require('eventproxy'); var config = require('../config'); var mysql = require('../common/mysql'); @@ -223,11 +224,26 @@ exports.removeByNameAndVersions = function (name, versions, callback) { mysql.query(DELETE_MODULE_BY_NAME_AND_VERSIONS_SQL, [name, versions], callback); }; -var LIST_BY_AUTHOR_SQL = 'SELECT name, package FROM module WHERE id IN \ +var LIST_RECENTLY_NAMES_SQL = 'SELECT distinct(name) AS name FROM module WHERE author = ? ORDER BY id DESC LIMIT 100;'; +var LIST_BY_NAMES_SQL = 'SELECT name, package FROM module WHERE id IN \ ( \ - SELECT module_id FROM tag WHERE tag="latest" AND name IN \ - (SELECT distinct(name) FROM module WHERE author = ? ORDER BY id DESC LIMIT 10) \ - );'; + SELECT module_id FROM tag WHERE tag="latest" AND name IN (?) \ + ) ORDER BY id DESC;'; exports.listByAuthor = function (author, callback) { - mysql.query(LIST_BY_AUTHOR_SQL, [author], callback); + var ep = eventproxy.create(); + ep.fail(callback); + mysql.query(LIST_RECENTLY_NAMES_SQL, [author], ep.done(function (rows) { + if (!rows || rows.length === 0) { + return callback(null, []); + } + ep.emit('names', rows.map(function (r) { + return r.name; + })); + })); + ep.on('names', function (names) { + mysql.query(LIST_BY_NAMES_SQL, [names], ep.done('modules')); + }); + ep.on('modules', function (modules) { + callback(null, modules); + }); }; diff --git a/test/proxy/module.test.js b/test/proxy/module.test.js index 37370e080..6e7687630 100644 --- a/test/proxy/module.test.js +++ b/test/proxy/module.test.js @@ -31,4 +31,17 @@ describe('proxy/module.test.js', function () { }); }); }); + + describe('listByAuthor()', function () { + it('should return author recent modules', function (done) { + Module.listByAuthor('fengmk2', function (err, rows) { + should.not.exist(err); + rows.forEach(function (r) { + r.should.have.keys('name', 'package'); + }); + done(); + }); + }); + }); + }); diff --git a/view/web/profile.html b/view/web/profile.html index 8f6e3428f..1793fcf05 100644 --- a/view/web/profile.html +++ b/view/web/profile.html @@ -13,7 +13,7 @@