def lut_write_to_cache_sql_mode(lut_key)
      batch_count = 0

      self.where(lut_options(lut_key)[:where]).find_in_batches(:batch_size => lut_options(lut_key)[:batch_size]) do |items| #FIXME not DRY here
        lut   = {}
        block = lut_proc(lut_key)

        items.each do |item|
          if block
            block.call(lut, item)
          else
            # HACK: doing a merge w/o replacing, just add elements for childs and may transform elements to array
            k = item.send(lut_key)
            v = item.id
            if lut[k]
              v      = [v]      unless v.respond_to?(:concat)
              lut[k] = [lut[k]] unless lut[k].respond_to?(:concat)
              lut[k].concat(v)
            else
              lut[k] = v
            end
          end
        end

        batch_count = self.lut_write_cache_item(lut_key, batch_count, lut)
        batch_count += 1
      end

      batch_count
    end
def lut_write_to_cache_sql_mode(lut_key)
      batch_count = 0

      self.where(lut_options(lut_key)[:where]).find_in_batches(:batch_size => lut_options(lut_key)[:batch_size]) do |items| #FIXME not DRY here
        lut   = {}
        block = lut_proc(lut_key)

        items.each do |item|
          if block
            block.call(lut, item)
          else
            # HACK: doing a merge w/o replacing, just add elements for childs and may transform elements to array
            k = item.send(lut_key)
            v = item.id
            if lut[k]
              v      = [v]      unless v.respond_to?(:concat)
              lut[k] = [lut[k]] unless lut[k].respond_to?(:concat)
              lut[k].concat(v)
            else
              lut[k] = v
            end
          end
        end

        batch_count = self.lut_write_cache_item(lut_key, batch_count, lut)
        batch_count += 1
      end

      batch_count
    end
HACK: somehow long method