Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 03b0e54

Browse files
Merge pull request #68 from Human-Connection/performance-optimization
Performance optimization
2 parents deab057 + b3f6601 commit 03b0e54

26 files changed

+542
-148
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5.
8181
We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice.
8282
You can install it locally if you like but this is totally optional.
8383
84-
- At first you have to [install](http://thumbor.readthedocs.io/en/latest/installing.html) it locally.
85-
- After installation start it via the console with `thumbor`
86-
- Set the `thumbor.url` in `config/local.json` to `http://localhost:8888` if not defined differently. The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure.
84+
**Install OR use docker**
85+
86+
- At first you have to [install](http://thumbor.readthedocs.io/en/latest/installing.html) it locally and start it in the console with `thumbor` **OR** run it with docker `docker run -p 8000:8000 apsl/thumbor`
87+
- Set the `thumbor.url` in `config/local.json` to `http://localhost:8888` (with docker `http://localhost:8000`) if not defined differently. The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure.
8788
8889
> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.
8990

server/helper/alter-items.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = func => hook => {
1414
}
1515
let items = getItems(hook);
1616
if (Array.isArray(items)) {
17-
items.map(item => func(item, hook));
17+
items = items.map(item => func(item, hook));
1818
} else if (items) {
1919
items = func(items, hook);
2020
}

server/helper/get-unique-slug.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const getUniqueSlug = (service, slug, count, id) => {
1313
};
1414
}
1515
service.find({
16-
query
16+
query,
17+
_populate: 'skip'
1718
}).then((result) => {
1819
if (result.data.length > 0) {
1920
count = count ? count + 1 : 1;

server/helper/seed-helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ module.exports = {
7171
return _.shuffle(ngoLogos).pop();
7272
},
7373
randomUnsplashUrl: () => {
74+
if (Math.random() < 0.6) {
75+
// do not attach images in 60 percent of the cases (faster seeding)
76+
return;
77+
}
7478
if (unsplashTopicsTmp.length < 2) {
7579
unsplashTopicsTmp = _.shuffle(unsplashTopics);
7680
}

server/hooks/create-slug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (options = { field: null, overwrite: false, unique: tr
1616
const titleSlug = slug(hook.data[options.field], {
1717
lower: true
1818
});
19-
if (options.unique) {
19+
if (options.unique !== false) {
2020
getUniqueSlug(hook.service, titleSlug, null, hook.id)
2121
.then((uniqueSlug) => {
2222
hook.data.slug = uniqueSlug;

server/hooks/is-single-item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Check if the query is for a single item
22
module.exports = () => hook => {
3-
if (hook && hook.params && hook.params.query && hook.params.query.$limit === 1) {
3+
if (hook && hook.params && hook.params.query && (hook.params.query.$limit === 1 || hook.params.query.slug)) {
44
return true;
55
} else {
66
return false;

server/hooks/save-remote-images.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Use this hook to manipulate incoming or outgoing data.
22
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
33

4-
const errors = require('feathers-errors');
4+
/**
5+
* TODO: Refactor and test that hook
6+
*/
57
const { isEmpty } = require('lodash');
68
const fs = require('fs');
79
const path = require('path');
@@ -29,7 +31,7 @@ function createUploadDirIfNeeded () {
2931
module.exports = function (options = []) { // eslint-disable-line no-unused-vars
3032
return function async (hook) {
3133

32-
return new Promise((resolve, reject) => {
34+
return new Promise((resolve) => {
3335

3436
let urls = [];
3537

@@ -78,8 +80,10 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
7880
resolve(hook);
7981
}
8082
} catch (err) {
83+
loading--;
84+
hook.data[field] = null;
8185
hook.app.error(err);
82-
reject(err);
86+
// reject(err);
8387
}
8488
} else if (validUrl.isUri(hook.data[field])) {
8589
// hook.app.debug('SAVE REMOTE IMAGES HOOK');
@@ -91,14 +95,20 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
9195
}, (err, res, body) => {
9296
if (err) {
9397
hook.app.error(err);
94-
reject(err);
98+
loading--;
99+
hook.data[field] = null;
100+
return;
101+
// reject(err);
95102
}
96103
// hook.app.debug(`###got answer for: ${hook.data[field]}`);
97104
try {
98105
const mimeType = res.headers['content-type'];
99106
if (mimeType.indexOf('image') !== 0) {
100107
hook.app.error('its not an image');
101-
reject(new Error('its not an image'));
108+
loading--;
109+
hook.data[field] = null;
110+
return;
111+
// reject(new Error('its not an image'));
102112
}
103113

104114
const ext = mime.getExtension(mimeType);
@@ -121,7 +131,9 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
121131
}
122132
} catch (err) {
123133
hook.app.error(err);
124-
reject(err);
134+
loading--;
135+
hook.data[field] = null;
136+
// reject(err);
125137
}
126138
});
127139
} else {
@@ -138,10 +150,11 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
138150
resolve(hook);
139151
}
140152
} catch (err) {
141-
// reject(err);
153+
// // reject(err);
142154
if (imgCount) {
143155
hook.app.error('Thumbnail download failed');
144-
throw new errors.Unprocessable('Thumbnail download failed', { errors: err, urls: urls });
156+
// throw new errors.Unprocessable('Thumbnail download failed', { errors: err, urls: urls });
157+
resolve(hook);
145158
} else {
146159
resolve(hook);
147160
}

server/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ logger.add(new transports.Console({
2222
return `${levelColors[info.level]}${date.toLocaleTimeString()} | ${info.level}: ${JSON.stringify(info.message)}\u001b[39m`;
2323
})
2424
),
25-
level: env === 'development' ? 'debug' : 'warn'
25+
level: env === 'development' || 'test' ? 'debug' : 'warn'
2626
}));
2727
module.exports = logger;

server/seeder/development/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function () {
1212
require('./candos'),
1313
require('./users-candos'),
1414
require('./projects'),
15-
// require('./follows'),
15+
require('./follows'),
1616
require('./comments'),
1717
require('./emotions'),
1818
require('./invites'),

server/seeder/development/users-candos.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (seederstore) => {
55

66
return {
77
services: [{
8-
count: 80,
8+
count: 50,
99
path: 'users-candos',
1010
templates: [
1111
{
@@ -28,4 +28,4 @@ module.exports = (seederstore) => {
2828
]
2929
}]
3030
};
31-
};
31+
};

0 commit comments

Comments
 (0)