82
82
w = read_weave(self._get(file_id))
83
83
transaction.map.add_weave(file_id, w)
84
84
transaction.register_clean(w, precious=self._precious)
85
# TODO: jam 20051219 This should check if there is a prelude
86
# which is already cached, and if so, should remove it
87
# But transaction doesn't seem to have a 'remove'
88
# One workaround would be to re-add the object with
92
def get_weave_prelude(self, file_id, transaction):
94
weave = transaction.map.find_weave(weave_id)
96
mutter("cache hit in %s for %s", self, weave_id)
98
# We want transactions to also cache preludes if that
99
# is all that we are loading. So we need a unique
100
# identifier, so that someone who wants the whole text
101
# won't get just the prelude
102
weave_id = 'PRELUDE-' + file_id
103
weave = transaction.map.find_weave(weave_id)
105
mutter("cache hit in %s for %s", self, weave_id)
107
w = read_weave(self._get(file_id), prelude=True)
108
transaction.map.add_weave(weave_id, w)
109
transaction.register_clean(w, precious=self._precious)
87
112
def get_lines(self, file_id, rev_id, transaction):
94
119
def get_weave_prelude_or_empty(self, file_id, transaction):
95
120
"""cheap version that reads the prelude but not the lines
97
weave = transaction.map.find_weave(file_id)
99
mutter("cache hit in %s for %s", self, file_id)
102
return read_weave(self._get(file_id),prelude=True)
123
return self.get_weave_prelude(file_id, transaction)
103
124
except NoSuchFile:
104
return Weave(weave_name=file_id)
125
# We can cache here, because we know that there
126
# is no complete object, since we got NoSuchFile
127
weave = Weave(weave_name=file_id)
128
transaction.map.add_weave(file_id, weave)
129
transaction.register_clean(weave, precious=self._precious)
106
132
def get_weave_or_empty(self, file_id, transaction):
107
133
"""Return a weave, or an empty one if it doesn't exist."""