Add RecalculateCaches to every level in hierarchy

This to decouple the implementation of recalculating caches from the
structure of the hierarchy: holder > index > frame > view > fragment.
See [Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter).
This commit is contained in:
Charlie Andrews 2017-10-11 09:36:32 -05:00
parent 9954bdd340
commit b6509a3ad7
4 changed files with 26 additions and 17 deletions

View file

@ -543,6 +543,13 @@ func (f *Frame) Views() []*View {
return other
}
// RecalculateCaches recalculates caches on every view in the frame.
func (f *Frame) RecalculateCaches() {
for _, view := range f.Views() {
view.RecalculateCaches()
}
}
// CreateViewIfNotExists returns the named view, creating it if necessary.
func (f *Frame) CreateViewIfNotExists(name string) (*View, error) {
// Don't create inverse views if they are not enabled.

View file

@ -361,25 +361,13 @@ func (h *Holder) flushCaches() {
}
}
// RecalculateCaches calls RecalculateCache on every fragment of every frame of
// every index. This is probably not practical to call in real-world workloads,
// but makes writing integration tests much eaiser, since one doesn't have to
// wait 10 seconds after setting bits to get expected response.
// RecalculateCaches recalculates caches on every index in the holder. This is
// probably not practical to call in real-world workloads, but makes writing
// integration tests much eaiser, since one doesn't have to wait 10 seconds
// after setting bits to get expected response.
func (h *Holder) RecalculateCaches() {
for _, index := range h.Indexes() {
for _, frame := range index.Frames() {
for _, view := range frame.Views() {
for _, fragment := range view.Fragments() {
select {
case <-h.closing:
return
default:
}
fragment.RecalculateCache()
}
}
}
index.RecalculateCaches()
}
}

View file

@ -392,6 +392,13 @@ func (i *Index) Frames() []*Frame {
return a
}
// RecalculateCaches recalculates caches on every frame in the index.
func (i *Index) RecalculateCaches() {
for _, frame := range i.Frames() {
frame.RecalculateCaches()
}
}
// CreateFrame creates a frame.
func (i *Index) CreateFrame(name string, opt FrameOptions) (*Frame, error) {
i.mu.Lock()

View file

@ -213,6 +213,13 @@ func (v *View) Fragments() []*Fragment {
return other
}
// RecalculateCaches recalculates the cache on every fragment in the view.
func (v *View) RecalculateCaches() {
for _, fragment := range v.Fragments() {
fragment.RecalculateCache()
}
}
// CreateFragmentIfNotExists returns a fragment in the view by slice.
func (v *View) CreateFragmentIfNotExists(slice uint64) (*Fragment, error) {
v.mu.Lock()