Address review comments:
authorWard Vandewege <ward@curoverse.com>
Wed, 31 Dec 2014 15:00:21 +0000 (10:00 -0500)
committerWard Vandewege <ward@curoverse.com>
Wed, 31 Dec 2014 15:00:21 +0000 (10:00 -0500)
* change stale_conflicting_nodes to a local variable
* minor performance optimization: add an additional check for ip_address being nil

refs #4887

services/api/app/models/node.rb

index 3bc25863e2e1ce4ad8d6fab49f63a4bcc8969789..c38f6817dbc768f4b380c51b999d75c6526dff61 100644 (file)
@@ -137,13 +137,15 @@ class Node < ArvadosModel
 
   def dns_server_update
     if self.hostname_changed? or self.ip_address_changed?
-      @stale_conflicting_nodes = Node.where('id != ? and ip_address = ? and last_ping_at < ?',self.id,self.ip_address,10.minutes.ago)
-      if not @stale_conflicting_nodes.empty?
-        # One or more stale compute node records have the same IP address as the new node.
-        # Clear the ip_address field on the stale nodes.
-        @stale_conflicting_nodes.each do |stale_node|
-          stale_node.ip_address = nil
-          stale_node.save!
+      if not self.ip_address.nil?
+        stale_conflicting_nodes = Node.where('id != ? and ip_address = ? and last_ping_at < ?',self.id,self.ip_address,10.minutes.ago)
+        if not stale_conflicting_nodes.empty?
+          # One or more stale compute node records have the same IP address as the new node.
+          # Clear the ip_address field on the stale nodes.
+          stale_conflicting_nodes.each do |stale_node|
+            stale_node.ip_address = nil
+            stale_node.save!
+          end
         end
       end
       if self.hostname and self.ip_address