Skip to content

Dirty-tracking for not-changes attributes? #31

Description

@dmke

I'm currently importing a larger number of configurations from different sources into Netbox, and this causes a lot of (unnecessary) PATCH requests.

Let's say I've got this device role, created by a previous import run:

role = NetboxClientRuby.dcim.device_roles.find_by(slug: "access-point")
#=> #<NetboxClientRuby::DCIM::DeviceRole @data={"id"=>6, "name"=>"Access Point", "slug"=>"access-point", "color"=>"009688", "vm_role"=>false}, @dirty_data={}, @id=6>

When setting its attributes, it gets tracked:

role.name = role.name
role.send :dirty_data
#=> {"name"=>"Access Point"}

Should NetboxClientRuby::Entity#method_missing track dirty attributes when the value did not change?

The patch should be relatively easy:

@@ lib/netbox_client_ruby/entity.rb @@
     def method_missing(name_as_symbol, *args, &block)
       if name.end_with?('=')
          ...
+        dirty_data[name[0..-2]] = args[0] unless dirty_data[name[0..-2]] == args[0] 
-        dirty_data[name[0..-2]] = args[0]
         return arg[0]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions