MCPcopy Index your code
hub / github.com/diffgram/diffgram / build_instance_preview_dict

Method build_instance_preview_dict

shared/database/video/sequence.py:181–208  ·  view source on GitHub ↗

Store cache here as getting instance for each thing is very time consuming. In current setup is a DB call for each. Probably some way to batch that but less composable. Caching reduced time from 20 seconds to 200 ms or so. Basic time based cache invalidation

(self, session = None)

Source from the content-addressed store, hash-verified

179 }
180
181 def build_instance_preview_dict(self, session = None):
182 """
183 Store cache here as getting instance for each thing is very time
184 consuming. In current setup is a DB call for each.
185 Probably some way to batch that but less composable.
186 Caching reduced time from 20 seconds to 200 ms or so.
187
188 Basic time based cache invalidation.
189 This wouldn't work in the exporting context where we set a time in
190 advance. See that exporting for it.
191
192 We still need to occasionally regenerate it for the signed URLs if nothing else
193 """
194 if self.cache_expiry is None or \
195 self.cache_expiry <= time.time():
196
197 if session:
198
199 instance = self.get_preview_instance(session = session)
200
201 if instance:
202 logger.debug(f"Rebuilding Instance {instance.id} Preview")
203
204 self.instance_preview_cache = instance.serialize_for_sequence_preview(
205 session = session)
206 self.cache_expiry = time.time() + 2591000
207 session.add(self)
208 return self.instance_preview_cache
209
210
211 def get_preview_instance(self, session):

Callers 2

Calls 3

get_preview_instanceMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected