MCPcopy Index your code
hub / github.com/git-bug/git-bug / entityUpdated

Method entityUpdated

cache/subcache.go:586–615  ·  view source on GitHub ↗

entityUpdated is a callback to trigger when the excerpt of an entity changed

(id entity.Id)

Source from the content-addressed store, hash-verified

584
585// entityUpdated is a callback to trigger when the excerpt of an entity changed
586func (sc *SubCache[EntityT, ExcerptT, CacheT]) entityUpdated(id entity.Id) error {
587 sc.mu.Lock()
588 e, ok := sc.cached[id]
589 if !ok {
590 sc.mu.Unlock()
591
592 // if the bug is not loaded at this point, it means it was loaded before
593 // but got evicted. Which means we potentially have multiple copies in
594 // memory and thus concurrent write.
595 // Failing immediately here is the simple and safe solution to avoid
596 // complicated data loss.
597 return errors.New("entity missing from cache")
598 }
599 sc.lru.Get(id)
600 // sc.excerpts[id] = bug2.NewBugExcerpt(b.bug, b.Snapshot())
601 sc.excerpts[id] = sc.makeExcerpt(e)
602 sc.mu.Unlock()
603
604 index, err := sc.repo.GetIndex(sc.namespace)
605 if err != nil {
606 return err
607 }
608
609 err = index.IndexOne(e.Id().String(), sc.makeIndexData(e))
610 if err != nil {
611 return err
612 }
613
614 return sc.write()
615}
616
617// evictIfNeeded will evict an entity from the cache if needed
618func (sc *SubCache[EntityT, ExcerptT, CacheT]) evictIfNeeded() {

Callers 4

addMethod · 0.95
finishIdentityMethod · 0.80
notifyUpdatedMethod · 0.80
notifyUpdatedMethod · 0.80

Calls 8

writeMethod · 0.95
GetMethod · 0.80
LockMethod · 0.65
GetIndexMethod · 0.65
IndexOneMethod · 0.65
StringMethod · 0.65
IdMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected