<commit_before>import os
from collections import deque

from ..models.base import ModelWithIDs, SourcedModelMixin


class CacheItem:
    def __init__(self, cache, obj):
        self.cache = cache
        self.obj = obj.sourced()
        self.referenced_by = set()
        self.references = set()
        self.ids = set(((obj.Model, )+id_) for id_ in obj.ids.items())
        self.i = None

    def add_to_cache(self):
        if self.i is not None:
            raise TypeError('Item was already added to cache!')

        # add the data, the ids, and start refer-lists
        self.i = len(self.cache._items)
        self.cache._items.append(self)
        for id_ in self.ids:
            self.cache._items_by_id[id_] = self
<commit_msg>only call sourced() once in cache per object<commit_after>import os
from collections import deque

from ..models.base import ModelWithIDs, SourcedModelMixin


class CacheItem:
    def __init__(self, cache, obj):
        self.cache = cache
        self.obj = obj
        self.referenced_by = set()
        self.references = set()
        self.ids = set(((obj.Model, )+id_) for id_ in obj.ids.items())
        self.i = None

    def add_to_cache(self):
        if self.i is not None:
            raise TypeError('Item was already added to cache!')

        # add the data, the ids, and start refer-lists
        self.i = len(self.cache._items)
        self.cache._items.append(self)
        for id_ in self.ids:
            self.cache._items_by_id[id_] = self

{'fraction_non_alphanumeric': 0.10234113712374582, 'fraction_numerical': 0.0, 'mean_word_length': 2.30242825607064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3365747', 'n_tokens_mistral': 467, 'n_tokens_neox': 456, 'n_words': 137}