Compare commits

...

9 Commits
2.2.0 ... 1.7.4

Author SHA1 Message Date
dead_horse
d03b9e159f Release 1.7.4 2014-11-25 12:56:48 +08:00
Yiyu He
63d148c1a5 Merge pull request #516 from CatTail/1.x
Add search package by keyword
2014-11-25 12:54:21 +08:00
zhongchiyu
dbd38ee6e7 Add unit test for searchbykeyword 2014-11-25 12:14:03 +08:00
zhongchiyu
df3a20df26 Add search package by keyword 2014-11-25 11:18:24 +08:00
fengmk2
5bb836381f Release 1.7.3 2014-11-12 16:59:14 +08:00
fengmk2
db73b9a675 fix(sync): should not sync package when maintainers sort change
Closes #500
2014-11-12 16:57:37 +08:00
fengmk2
6ca71e1d8b Release 1.7.2 2014-10-31 14:28:30 +08:00
Yiyu He
ff811ab15e Merge pull request #487 from cnpm/min-sync-interval
feat(sync): add min sync interval time detect
2014-10-31 14:21:39 +08:00
fengmk2
ae1ca1bc32 feat(sync): add min sync interval time detect
Forbidden some guy write `config.syncInterval = 1` to let sync too fast.

Closes #486
2014-10-31 14:18:58 +08:00
8 changed files with 76 additions and 9 deletions

View File

@@ -1,4 +1,21 @@
1.7.4 / 2014-11-25
==================
* Merge pull request [#516](https://github.com/cnpm/cnpmjs.org/issues/516) from CatTail/1.x
* Add unit test for searchbykeyword
* Add search package by keyword
1.7.3 / 2014-11-12
==================
* fix(sync): should not sync package when maintainers sort change
1.7.2 / 2014-10-31
==================
* feat(sync): add min sync interval time detect
1.7.1 / 2014-10-15
==================

View File

@@ -1059,3 +1059,10 @@ exports.updateTag = function* () {
ok: true
};
};
exports.searchByKeyword = function* () {
var packages = yield Module.searchByKeyword(this.params.keyword, {});
this.body = {
packages: packages
};
};

View File

@@ -1,6 +1,6 @@
{
"name": "cnpmjs.org",
"version": "1.7.1",
"version": "1.7.4",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
@@ -90,5 +90,8 @@
"fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)",
"dead_horse <dead_horse@qq.com> (http://deadhorse.me)"
],
"publishConfig": {
"tag": "v1"
},
"license": "MIT"
}

View File

@@ -572,6 +572,13 @@ exports.search = function (word, options, callback) {
});
};
exports.searchByKeyword = function (keyword, options, callback) {
var limit = options.limit || 100;
mysql.query(SEARCH_MODULES_BY_KEYWORD_SQL, [ keyword, limit ], function(err, rows) {
callback(null, rows);
});
};
thunkify(exports);
var GET_LAST_MODIFIED_MODULE_SQL = multiline(function () {;/*

View File

@@ -549,13 +549,8 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
if (!version.maintainers || !version.maintainers[0]) {
version.maintainers = pkg.maintainers;
}
var sourceAuthor = version.maintainers && version.maintainers[0] &&
version.maintainers[0].name || exists.author;
if (exists.package &&
exists.package.dist.shasum === version.dist.shasum &&
exists.author === sourceAuthor) {
// * author make sure equal
exists.package.dist.shasum === version.dist.shasum) {
// * shasum make sure equal
if ((version.publish_time === exists.publish_time) ||
(!version.publish_time && exists.publish_time)) {

View File

@@ -87,6 +87,9 @@ function routes(app) {
// list all packages of user
app.get('/-/by-user/:user', userPackage.list);
// search package by keyword
app.get('/-/by-keyword/:keyword', mod.searchByKeyword);
}
module.exports = routes;

View File

@@ -58,7 +58,7 @@ var handleSync = co(function *() {
var data;
var error;
try {
data = yield *sync();
data = yield* sync();
} catch (err) {
error = err;
error.message += ' (sync package error)';
@@ -74,7 +74,12 @@ var handleSync = co(function *() {
if (sync) {
handleSync();
setInterval(handleSync, ms(config.syncInterval));
var syncInterval = ms(config.syncInterval);
var minSyncInterval = ms('5m');
if (!syncInterval || syncInterval < minSyncInterval) {
syncInterval = minSyncInterval;
}
setInterval(handleSync, syncInterval);
}
/**

View File

@@ -100,6 +100,36 @@ describe('proxy/module.test.js', function () {
});
});
describe('searchByKeyword()', function () {
before(function (done) {
Module.addKeywords('bbbb', 'mock bbbbbb', ['aa', 'bb', 'cc'], function (err, results) {
should.not.exist(err);
results.should.be.an.Array;
results.should.length(3);
done();
});
});
it('should search match keywords modules', function(done) {
Module.searchByKeyword('aa', {}, function (err, data) {
should.not.exist(err);
data.length.should.above(0);
data.forEach(function (row) {
row.should.have.keys('name', 'description');
});
done();
});
});
it('should return empty array if not match found', function (done) {
Module.searchByKeyword('notexistkeyword', {}, function (err, data) {
should.not.exist(err);
data.should.eql([]);
done();
});
});
});
var mockName = 'aa' + Date.now();
describe('addKeywords()', function () {
it('should add diff keywords to module', function (done) {