Skip to content

Commit

Permalink
Merge pull request #327 from Codeminer42/fix-excessive-load
Browse files Browse the repository at this point in the history
remove trigger for all time call signature
  • Loading branch information
andrerpbts committed Feb 16, 2018
2 parents d6ebf70 + 06d1451 commit 4516b39
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Moved the story estimate buttons to a react component.
- Change in import project, switch button attachinary_file_field to file_field
- Change the verification to refuse if const files is null, otherwise return the value files
- Request signature for file uploads once and all stories get this from a global place

## [1.16.1] 2018-01-03
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"SIDEKIQ_CONCURRENCY": {
"description": "Sidekiq is used mostly for email notifications, so it's quite fast and can be highly parallelized",
"value": "20",
"value": "2",
"required": false
},
"WEB_CONCURRENCY": {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/models/attachmentOptions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const REFRESH_TIME = 3500000;
const REFRESH_TIME = 3600001;

export default class AttachmentOptions {

constructor({ refreshCallback }) {
this.refreshCallback = refreshCallback;
}
Expand All @@ -10,6 +9,7 @@ export default class AttachmentOptions {
return this.fetchOptions().then((response) => {
this.refreshCallback(response);
this.timestampVerifierId = this.initExpirationVerifier();
return response;
})
}

Expand All @@ -27,7 +27,7 @@ export default class AttachmentOptions {
}

initExpirationVerifier() {
setTimeout(() => {
return setTimeout(() => {
this.fetch();
}, REFRESH_TIME);
}
Expand Down
21 changes: 20 additions & 1 deletion app/assets/javascripts/views/project_view.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import AttachmentOptions from 'models/attachmentOptions'
import StoryAttachment from 'components/story/StoryAttachment';
var StoryView = require('./story_view');
var IterationView = require('./iteration_view');
var ColumnView = require('./column_view');
Expand All @@ -23,6 +25,15 @@ module.exports = Backbone.View.extend({
this.prepareColumns();
this.$loadingSpin.show();
this.model.stories.fetch({success: this.addAll});

const attachmentOptions = new AttachmentOptions({
refreshCallback: (options) => {
this.attachmentOptions = options;
this.trigger('attachmentOptions', options);
}
});

attachmentOptions.fetch();
},

prepareColumns: function() {
Expand Down Expand Up @@ -84,7 +95,15 @@ module.exports = Backbone.View.extend({
if (_.isUndefined(column) || !_.isString(column)) {
column = story.column;
}
var view = new StoryView({model: story}).render();
var view = new StoryView({
model: story,
attachmentOptions: this.attachmentOptions
}).render();

view.listenTo(this, 'attachmentOptions', (options) => {
view.trigger('attachmentOptions', options);
});

this.appendViewToColumn(view, column);
view.setFocus();
if (column === '#done') {
Expand Down
26 changes: 14 additions & 12 deletions app/assets/javascripts/views/story_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ module.exports = FormView.extend({
// Set up CSS classes for the view
this.setClassName();

this.attachinaryOptions = {}
this.fetchAttachinaryOptions();
},
this.on('attachmentOptions', (options) => {
this.attachmentOptions = options;
if(this.canEdit()) {
// attachinary won't re-create the instance with the new
// signature if the instance for the element is already created
if(this.$('.attachinary-input').data('attachinary-bond')) {
this.$('.attachinary-input')
.fileupload('destroy')
.data('attachinary-bond').initFileUpload();
}

fetchAttachinaryOptions: function() {
const attachmentOptions = new AttachmentOptions({
refreshCallback: this.setAttachinaryOptions.bind(this)
this.renderAttachments();
}
});
attachmentOptions.fetch();
},

setAttachinaryOptions: function(options) {
this.attachinaryOptions = options;
this.render();
this.attachmentOptions = options.attachmentOptions;
},

isReadonly: function() {
Expand Down Expand Up @@ -645,7 +647,7 @@ module.exports = FormView.extend({
name='attachments'
isReadonly={this.isReadonly()}
filesModel={this.model.get('documents')}
options={this.attachinaryOptions}
options={this.attachmentOptions}
/>,
attachments
);
Expand Down
75 changes: 75 additions & 0 deletions spec/javascripts/models/attachment_options_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import AttachmentOptions from 'models/attachmentOptions';

describe("AttachmentOptions", function() {
let refreshCallback;
let attachinaryJSON = {
"attachinary": {
"accessible": true,
"accept": ["raw", "jpg", "png", "psd", "docx", "xlsx", "doc", "xls"],
"maximum": 10,
"single": false,
"scope": "documents",
"plural": "documents",
"singular": "document",
"files": []
},
"cloudinary": {
"tags": ["development_env", "attachinary_tmp"],
"use_filename": true
},
"html": {
"class": ["attachinary-input"],
"accept": "image/jpeg,image/png,image/vnd.adobe.photoshop,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/excel",
"multiple": true,
"data": {
"attachinary": {
"accessible": true,
"accept": ["raw", "jpg", "png", "psd", "docx", "xlsx", "doc", "xls"],
"maximum": 10,
"single": false,
"scope": "documents",
"plural": "documents",
"singular": "document",
"files": []
},
"form_data": {
"timestamp": 1435347909,
"callback": "http://localhost:3000/attachinary/cors",
"tags": "development_env,attachinary_tmp",
"signature": "db3b029ed02431b1dccac45cc8b2159a280fd334",
"api_key": "893592954749395"
},
"url": "https://api.cloudinary.com/v1_1/hq5e5afno/auto/upload"
}
}
}

beforeEach(function(done) {
refreshCallback = sinon.spy();

let attachmentOptions = new AttachmentOptions({ refreshCallback });

this.server = sinon.fakeServer.create();

this.server.respondWith(
"GET", "/attachments/signature", [
200, {"Content-Type": "application/json"},
JSON.stringify(attachinaryJSON)
]
);

attachmentOptions.fetch().then(() => {
done();
});

this.server.respond();
});

afterEach(function() {
this.server.restore();
});

it("fetch return a signature", function() {
expect(refreshCallback).toHaveBeenCalledWith(attachinaryJSON);
});
});
41 changes: 41 additions & 0 deletions spec/javascripts/views/story_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,47 @@ describe('StoryView', function() {

beforeEach(function() {
this.view.model.set({editing: true});
this.view.trigger('attachmentOptions', {
"attachinary": {
"accessible": true,
"accept": ["raw", "jpg", "png", "psd", "docx", "xlsx", "doc", "xls"],
"maximum": 10,
"single": false,
"scope": "documents",
"plural": "documents",
"singular": "document",
"files": []
},
"cloudinary": {
"tags": ["development_env", "attachinary_tmp"],
"use_filename": true
},
"html": {
"class": ["attachinary-input"],
"accept": "image/jpeg,image/png,image/vnd.adobe.photoshop,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/excel",
"multiple": true,
"data": {
"attachinary": {
"accessible": true,
"accept": ["raw", "jpg", "png", "psd", "docx", "xlsx", "doc", "xls"],
"maximum": 10,
"single": false,
"scope": "documents",
"plural": "documents",
"singular": "document",
"files": []
},
"form_data": {
"timestamp": 1435347909,
"callback": "http://localhost:3000/attachinary/cors",
"tags": "development_env,attachinary_tmp",
"signature": "db3b029ed02431b1dccac45cc8b2159a280fd334",
"api_key": "893592954749395"
},
"url": "https://api.cloudinary.com/v1_1/hq5e5afno/auto/upload"
}
}
});
});

afterEach(function() {
Expand Down

0 comments on commit 4516b39

Please sign in to comment.