entityUpdated is a callback to trigger when the excerpt of an entity changed
(id entity.Id)
| 584 | |
| 585 | // entityUpdated is a callback to trigger when the excerpt of an entity changed |
| 586 | func (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 |
| 618 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) evictIfNeeded() { |
no test coverage detected