Code Monkey home page Code Monkey logo

Comments (2)

catmando avatar catmando commented on June 15, 2024

It seems that this fix is working (see notes below)

module ReactiveRecord
  class Broadcast

    def self.after_commit(operation, model)
      # Calling public_columns_hash once insures all policies are loaded
      # before the first broadcast.
      @public_columns_hash ||= ActiveRecord::Base.public_columns_hash
      Hyperstack::InternalPolicy.regulate_broadcast(model) do |data|
        # filter out any unchanged fields unless its a create operation in which case we want to send everything
        # allowed by the policies.
        filter_unchanged_fields!(model.class.primary_key.to_sym, data) if operation != :create
        puts "Broadcast aftercommit hook: #{data}" if Hyperstack::Connection.show_diagnostics

        if !Hyperstack.on_server? && Hyperstack::Connection.root_path
          send_to_server(operation, data, model.__synchromesh_update_time) rescue nil # fails if server no longer running so ignore
        else
          SendPacket.run(data, operation: operation, updated_at: model.__synchromesh_update_time)
        end
      end
    rescue ActiveRecord::StatementInvalid => e
      raise e unless e.message == "Could not find table 'hyperstack_connections'"
    end unless RUBY_ENGINE == 'opal'

    def self.filter_unchanged_fields!(primary_key, data)
      data[:record] = data[:record].filter do |field, _| 
        data[:previous_changes].key?(field) || field == primary_key
      end
    end unless RUBY_ENGINE == 'opal'
....

Adding this causes this spec to fail: ./spec/batch5/authorization_spec.rb:113

It seems that spec itself is very brittle, and should be rewritten. It fails in a couple of places because it is in fact assuming that all data is being sent down even fields that have not changed. The spec uses some methods to interrogate the data on the client, without using the normal client interface. I do not believe an actual working application would have any problems.

from hyperstack.

catmando avatar catmando commented on June 15, 2024

So the reason that this was changed to submit the entire record, is that when making multiple saves within an active-record transaction, only the last values saved by previous_changes will be saved. The ar_transaction_changes gem is a work around for this, but we should investigate a more efficient / complete solution.

from hyperstack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.