mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 17:15:31 +00:00
Added reset of Reverse Reference Rersolver on reparse
This commit is contained in:
15
providers/xmlprovider/library.go
Normal file
15
providers/xmlprovider/library.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package xmlprovider
|
||||
|
||||
import "sync"
|
||||
|
||||
type Library struct {
|
||||
pmux sync.Mutex
|
||||
Parses []ParseMeta
|
||||
}
|
||||
|
||||
func (l *Library) Latest() ParseMeta {
|
||||
if len(l.Parses) == 0 {
|
||||
return ParseMeta{}
|
||||
}
|
||||
return l.Parses[len(l.Parses)-1]
|
||||
}
|
||||
@@ -62,6 +62,7 @@ func (p *XMLProvider[T]) Prepare() {
|
||||
defer p.mu.Unlock()
|
||||
// INFO: We take 1000 here as to not reallocate the memory as mutch.
|
||||
p.Array = make([]T, 0, 1000)
|
||||
p.Resolver.Clear()
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) Serialize(dataholder XMLRootElement[T], path string, latest ParseMeta) error {
|
||||
@@ -82,15 +83,7 @@ func (p *XMLProvider[T]) Serialize(dataholder XMLRootElement[T], path string, la
|
||||
p.Items.Store(id, &item)
|
||||
}
|
||||
|
||||
// INFO: If the item has a GetReferences method, we add the references to the resolver.
|
||||
if rr, ok := any(item).(ReferenceResolver[T]); ok {
|
||||
for name, ids := range rr.References() {
|
||||
for _, res := range ids {
|
||||
res.Item = &item
|
||||
p.Resolver.Add(name, res.Reference, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.addResolvable(item)
|
||||
}
|
||||
|
||||
p.Array = append(p.Array, newItems...)
|
||||
@@ -131,6 +124,19 @@ func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
|
||||
|
||||
for _, item := range toappend {
|
||||
p.Array = append(p.Array, *item)
|
||||
p.addResolvable(*item)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) addResolvable(item T) {
|
||||
// INFO: If the item has a GetReferences method, we add the references to the resolver.
|
||||
if rr, ok := any(item).(ReferenceResolver[T]); ok {
|
||||
for name, ids := range rr.References() {
|
||||
for _, res := range ids {
|
||||
res.Item = &item
|
||||
p.Resolver.Add(name, res.Reference, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +169,14 @@ func (a *XMLProvider[T]) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) Info(id string) ItemInfo {
|
||||
info, ok := p.Infos.Load(id)
|
||||
if !ok {
|
||||
return ItemInfo{}
|
||||
}
|
||||
return info.(ItemInfo)
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) Item(id string) *T {
|
||||
item, ok := p.Items.Load(id)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user