ember.js - Rails ActionCable and Ember CLI app - Resource Bottlenecks -
we've implemented real time updates in our app using actioncable in rails , implemented consumer client service in ember cli, looking better, less-expensive approach.
app/models/myobj.rb
has_many :child_objs def after_commit actioncable.server.broadcast("obj_#{self.id}", model: "myobj", id: self.id) self.child_objs.update_all foo: bar end
app/models/child_obj.rb
belongs_to :myobj def change_job self.job = 'foo' self.save actioncable.server.broadcast("obj_#{self.myobj.id}", model: "child_obj", id: self.id) end
frontend/app/services/stream.js here we're taking model , id data broadcast , using reload server.
import ember 'ember'; export default ember.service.extend({ store: ember.inject.service(), subscribe(visitid) { let store = this.get("store") myactioncable.cable.subscriptions.create( {channel: "objchannel", id: objid}, { received(data) { store.findrecord(data.model, data.id, {reload: true}); } } ); }, });
this approach "works" feels naïve , resource intensive, hitting our server again each update, requires re-authenticating request, grabbing data database, re-serializing object (which have additional database pulls), , sending across wire. in fact cause pool , throttling issues if number of requests high.
i'm thinking potentially send model, id, , changeset (self.changes
) in rails broadcast, , have ember side handle setting appropriate model properties. correct approach, or there else recommends?
you should fine sending whole entity payload change event via sockets. later can push payload store - create new records or update existing. way you'll avoid additional server requests.
Comments
Post a Comment