Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

Don't send an updates to clients if the filtered changes are empty #107

Open
catmando opened this issue Jul 17, 2018 · 3 comments
Open

Don't send an updates to clients if the filtered changes are empty #107

catmando opened this issue Jul 17, 2018 · 3 comments

Comments

@catmando
Copy link
Contributor

when using auth_logic (for example) when a logged user makes ANY request to the server, this updates the user model, which causes data to be pushed to the client

which causes the client to update its scopes

which is another request

and so on...

so the solution should be don't sync those attributes to the client

so hyper-mesh filters out those attributes, but the problem is even if you have an empty set of attributes, the update is still being sent, causing the scope resync...

@catmando
Copy link
Contributor Author

this may fix it:

module ReactiveRecord
  class Broadcast
    def self.after_commit(operation, model)
      Hyperloop::InternalPolicy.regulate_broadcast(model) do |data|
        if !Hyperloop.on_server? && Hyperloop::Connection.root_path
          send_to_server(operation, data)
        elsif operation == :update && data[:previous_changes].empty?
          SendPacket.run(data, operation: operation)
        end
      end
    rescue ActiveRecord::StatementInvalid => e
      raise e unless e.message == "Could not find table 'hyperloop_connections'"
    end unless RUBY_ENGINE == 'opal'
  end
end

@catmando
Copy link
Contributor Author

catmando commented Jul 17, 2018

you can't monkey patch this but a slightly cleaner (if not quite as effecient) way is to change the SendPacket operation's dispatch to be:

dispatch_to { params.channel if params.operation == :update && params.previous_changes.present? }

@catmando
Copy link
Contributor Author

actually first case (patching after_commit) won't work if the change was made on the console... So best update SendPacket

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant