<commit_before>module Cache
  module Object
    class MultiGet
      attr_accessor :clazz

      def initialize(clazz)
        @clazz = clazz
      end

      def fetch_all(ids)
        objs = cached_objects(ids)
        remaining = missed_ids(ids, objs)
        return objs if remaining.empty?
        objs + load_from_db(remaining)
      end

      def load_from_db(ids)
        primary_key = @clazz.primary_key.to_sym
        @clazz.where(primary_key => ids).to_a.each(&:write_cache!)
      end

      def object_keys(ids)
        ids.map { |id| Cache::Object::KeyGenerator.key_for_object(@clazz.name, id) }
      end

      def cached_objects(ids)
        keys = object_keys(ids)
        Cache::Object.adapter.read_multi(keys).values
      end

      def missed_ids(ids, fetched_objects)
        ids - fetched_objects.map(&:id)
      end
    end
  end
end<commit_msg>reference accessor instead of instance variable<commit_after>module Cache
  module Object
    class MultiGet
      attr_reader :clazz

      def initialize(clazz)
        @clazz = clazz
      end

      def fetch_all(ids)
        objs = cached_objects(ids)
        remaining = missed_ids(ids, objs)
        return objs if remaining.empty?
        objs + load_from_db(remaining)
      end

      def load_from_db(ids)
        primary_key = clazz.primary_key.to_sym
        clazz.where(primary_key => ids).to_a.each(&:write_cache!)
      end

      def object_keys(ids)
        ids.map { |id| Cache::Object::KeyGenerator.key_for_object(clazz.name, id) }
      end

      def cached_objects(ids)
        keys = object_keys(ids)
        Cache::Object.adapter.read_multi(keys).values
      end

      def missed_ids(ids, fetched_objects)
        ids - fetched_objects.map(&:id)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08752117447769622, 'fraction_numerical': 0.0, 'mean_word_length': 2.330827067669173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '335366', 'n_tokens_mistral': 578, 'n_tokens_neox': 567, 'n_words': 116}