Skip to content

Commit b284f0d

Browse files
committed
always return exact match first and remove some logs
1 parent bf0095b commit b284f0d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

serverless/libs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports.cache = async (e) => {
1111
if (e.source === 'aws.events') return Promise.resolve({ statusCode: 204 });
1212
const { libs } = typeof e.body === 'string' ? JSON.parse(e.body) : e.body;
1313
const newLibs = [];
14-
console.log(libs);
14+
// console.log(libs);
1515

1616
await Promise.all(libs.map(async (lib) => {
1717
const path = libPath(lib.url);
@@ -31,7 +31,7 @@ module.exports.cache = async (e) => {
3131

3232
module.exports.save = async (e) => {
3333
const { libs } = e;
34-
console.log(libs);
34+
// console.log(libs);
3535

3636
await Promise.all(libs.map(async (lib) => {
3737
const path = libPath(lib.url);

serverless/s3.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const get = async (key, file) => {
1717

1818
const has = async (key) => {
1919
try {
20-
const res = await s3.headObject({ Key: key, Bucket: sls.custom.s3LibCache }).promise();
21-
console.log(res);
20+
// const res =
21+
await s3.headObject({ Key: key, Bucket: sls.custom.s3LibCache }).promise();
22+
// console.log(res);
2223
return true;
2324
} catch (err) {
2425
console.error(err);

src/actions/info.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ module.exports.server = (socket, done) => done && done({
1818

1919

2020
module.exports.librariesSearch = async (data, socket, done) => {
21-
console.log('loading in libs');
2221
const libs = await loadLibs();
23-
console.log('done loading in libs');
2422
const limit = Math.min(Math.max(data.limit || 10, 1), 100);
2523
const skip = Math.max(data.skip || 0, 0);
2624
const reg = searchRegex(data.search);
2725
const { sortBy = 'name' } = data;
2826
const sortDesc = !(typeof data.sortDesc === 'undefined' || `${data.sortDesc}` === 'false');
29-
const res = libs.filter((lib) => reg.test(lib.name)).sort((a, b) => {
30-
const ai = `${a[sortBy]}`.toLowerCase();
31-
const bi = `${b[sortBy]}`.toLowerCase();
32-
if (ai === bi) return 0;
33-
return (ai < bi ? -1 : 1) * (sortDesc ? -1 : 1);
34-
});
27+
const eq = (a, b) => a.toLowerCase() === b.toLowerCase();
28+
const res = [
29+
...libs.filter((lib) => eq(lib.name, data.search)),
30+
...libs.filter((lib) => !eq(lib.name, data.search) && reg.test(lib.name))
31+
.sort((a, b) => {
32+
const ai = `${a[sortBy]}`.toLowerCase();
33+
const bi = `${b[sortBy]}`.toLowerCase();
34+
if (ai === bi) return 0;
35+
return (ai < bi ? -1 : 1) * (sortDesc ? -1 : 1);
36+
}),
37+
];
3538
const response = {
3639
limit, skip, total: res.length, data: res.slice(skip * limit, (skip + 1) * limit),
3740
};

0 commit comments

Comments
 (0)