Skip to content

Commit

Permalink
Don't store indexes in project folder by default anymore due to CPU rise
Browse files Browse the repository at this point in the history
I wanted to place the index inside the .serenata folder, but it turns 
out that is a very bad idea. Atom will start firing massive amounts of 
change requests, due to it watching the database file, every time it is 
modified. We can disable this for our package, but not for other 
packages, which will still receive these events en masse uselessly, 
which not only prevents any other responses from being handled in the 
meantime, it also spikes CPU usage.

Existing indexes will continue to work, this just sets the default for 
new projects to be the php-ide-serenata cache folder. You can still opt 
to save them in the project, by changing it, if you want.

References #460
  • Loading branch information
Gert-dev committed Sep 9, 2019
1 parent c5465d8 commit e1b883f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions lib/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class ProjectManager
/**
* @param {Object} proxy
*/
constructor(proxy) {
constructor(proxy, config) {
this.proxy = proxy;
this.config = config;
this.activeProject = null;
}

Expand All @@ -32,9 +33,23 @@ class ProjectManager
// mainFolder = '/' + mainFolder.substr(0, 1).toLowerCase() + mainFolder.substr(1);
// }

const path = require('path');
const crypto = require('crypto');

const md5 = crypto.createHash('md5');
const configFileFolderPath = mainFolder + '/.serenata';
const configFilePath = configFileFolderPath + '/config.json';

// NOTE: I wanted to place the index inside the .serenata folder, but it turns out that is a very bad idea.
// Atom will start firing massive amounts of change requests, due to it watching the database file, every time
// it is modified. We can disable this for our package, but not for other packages, which will still receive
// these events en masse uselessly, which not only prevents any other responses from being handled in the
// meantime, it also spikes CPU usage.
const indexDatabaseUri = 'file://' + path.join(
this.config.get('storagePath'),
'index-' + md5.update(mainFolder).digest('hex') + '.sqlite'
);

if (fs.existsSync(configFilePath)) {
throw new Error(
'The currently active project was already initialized. To prevent existing settings from being ' +
Expand All @@ -47,7 +62,7 @@ class ProjectManager
"uris": [
"file://${mainFolder}"
],
"indexDatabaseUri": "file://${mainFolder}/.serenata/index.sqlite",
"indexDatabaseUri": "${indexDatabaseUri}",
"phpVersion": 7.3,
"excludedPathExpressions": [],
"fileExtensions": [
Expand Down
2 changes: 1 addition & 1 deletion lib/ServiceContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ServiceContainer
getProjectManager() {
if (this.projectManager === null) {
const ProjectManager = require('./ProjectManager');
this.projectManager = new ProjectManager(this.getProxy());
this.projectManager = new ProjectManager(this.getProxy(), this.getConfiguration());
}

return this.projectManager;
Expand Down

0 comments on commit e1b883f

Please sign in to comment.