Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
fix This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOM…
Browse files Browse the repository at this point in the history
…E subquery. fixed #54
  • Loading branch information
fengmk2 committed Dec 11, 2013
1 parent c4bc93f commit 50af7d2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
24 changes: 18 additions & 6 deletions common/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
26 changes: 21 additions & 5 deletions proxy/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

var utility = require('utility');
var eventproxy = require('eventproxy');
var config = require('../config');
var mysql = require('../common/mysql');

Expand Down Expand Up @@ -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);
});
};
13 changes: 13 additions & 0 deletions test/proxy/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

});
2 changes: 1 addition & 1 deletion view/web/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1>
Packages by <%= user.name %>
<% if (user.email) { %>
<small>(<a href="mailto:"<%= user.email %>><%= user.email %></a>)</small>
<small>(<a href="mailto:<%= user.email %>"><%= user.email %></a>)</small>
<% } %>
</h1>
<hr />
Expand Down

0 comments on commit 50af7d2

Please sign in to comment.