mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
BUGFIX: Reverse Lookups working
This commit is contained in:
@@ -142,14 +142,17 @@ func (p *XMLProvider[T]) ReverseLookup(item XMLItem) ([]Resolved[T], error) {
|
|||||||
return nil, fmt.Errorf("Item has no keys")
|
return nil, fmt.Errorf("Item has no keys")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// INFO: this runs just once for the first key
|
||||||
|
ret := make([]Resolved[T], 0)
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
ret, err := p.Resolver.Get(item.Name(), key)
|
r, err := p.Resolver.Get(item.Name(), key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, nil
|
return ret, err
|
||||||
}
|
}
|
||||||
|
ret = append(ret, r...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []Resolved[T]{}, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *XMLProvider[T]) String() string {
|
func (a *XMLProvider[T]) String() string {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,23 +19,12 @@ type AgentsListView struct {
|
|||||||
type AgentView struct {
|
type AgentView struct {
|
||||||
xmlmodels.Agent
|
xmlmodels.Agent
|
||||||
Works []WorkByAgent
|
Works []WorkByAgent
|
||||||
Pieces []PieceByAgent
|
Pieces []xmlprovider.Resolved[xmlmodels.Piece]
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkByAgent struct {
|
type WorkByAgent struct {
|
||||||
xmlmodels.Work
|
xmlprovider.Resolved[xmlmodels.Work]
|
||||||
Pieces []PieceByWork
|
Pieces []xmlprovider.Resolved[xmlmodels.Piece]
|
||||||
Reference xmlmodels.AgentRef
|
|
||||||
}
|
|
||||||
|
|
||||||
type PieceByAgent struct {
|
|
||||||
xmlmodels.Piece
|
|
||||||
Reference xmlmodels.AgentRef
|
|
||||||
}
|
|
||||||
|
|
||||||
type PieceByWork struct {
|
|
||||||
xmlmodels.Piece
|
|
||||||
Reference xmlmodels.WorkRef
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
||||||
@@ -62,40 +52,23 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We won't need to lock the library if we take down the server during parsing
|
// INFO: All lookups are O(1)
|
||||||
lib.Works.Lock()
|
for _, a := range res.Agents {
|
||||||
// for _, a := range res.Agents {
|
if works, err := lib.Works.ReverseLookup(a); err == nil {
|
||||||
//
|
for _, w := range works {
|
||||||
// }
|
if pieces, err := lib.Pieces.ReverseLookup(w.Item); err == nil {
|
||||||
// for _, w := range lib.Works.Array {
|
a.Works = append(a.Works, WorkByAgent{Resolved: w, Pieces: pieces})
|
||||||
// if ref, ok := w.ReferencesAgent(letterorid); ok {
|
|
||||||
// if entry, ok := res.Agents[ref.Ref]; ok {
|
|
||||||
// entry.Works = append(entry.Works, WorkByAgent{Work: w, Reference: *ref})
|
|
||||||
// res.Agents[ref.Ref] = entry
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
lib.Works.Unlock()
|
|
||||||
|
|
||||||
lib.Pieces.Lock()
|
|
||||||
for _, p := range lib.Pieces.Array {
|
|
||||||
if ref, ok := p.ReferencesAgent(letterorid); ok {
|
|
||||||
if entry, ok := res.Agents[ref.Ref]; ok {
|
|
||||||
entry.Pieces = append(entry.Pieces, PieceByAgent{Piece: p, Reference: *ref})
|
|
||||||
res.Agents[ref.Ref] = entry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PERF: This is really slow: resolve all backlinks after parse?
|
|
||||||
for _, a := range res.Agents {
|
|
||||||
for _, w := range a.Works {
|
|
||||||
if ref, ok := p.ReferencesWork(w.ID); ok {
|
|
||||||
w.Pieces = append(w.Pieces, PieceByWork{Piece: p, Reference: *ref})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pieces, err := lib.Pieces.ReverseLookup(a.Agent); err == nil {
|
||||||
|
a.Pieces = pieces
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: sort the things, also for works and pieces above
|
||||||
|
res.Agents[a.ID] = a
|
||||||
}
|
}
|
||||||
lib.Pieces.Unlock()
|
|
||||||
|
|
||||||
res.AvailableLetters = slices.Collect(maps.Keys(av))
|
res.AvailableLetters = slices.Collect(maps.Keys(av))
|
||||||
slices.Sort(res.AvailableLetters)
|
slices.Sort(res.AvailableLetters)
|
||||||
|
|||||||
@@ -45,10 +45,10 @@
|
|||||||
{{- if ne (len $a.Works) 0 -}}
|
{{- if ne (len $a.Works) 0 -}}
|
||||||
<div>
|
<div>
|
||||||
{{ range $_, $w := $a.Works }}
|
{{ range $_, $w := $a.Works }}
|
||||||
{{- if ne (len $w.Citation.InnerXML ) 0 -}}
|
{{- if ne (len $w.Item.Citation.InnerXML ) 0 -}}
|
||||||
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
|
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
|
||||||
<xml>
|
<xml>
|
||||||
{{- Safe $w.Citation.InnerXML -}}
|
{{- Safe $w.Item.Citation.InnerXML -}}
|
||||||
</xml>
|
</xml>
|
||||||
</script>
|
</script>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
{{- if ne (len $a.Pieces) 0 -}}
|
{{- if ne (len $a.Pieces) 0 -}}
|
||||||
<div>
|
<div>
|
||||||
{{ range $_, $p := $a.Pieces }}
|
{{ range $_, $p := $a.Pieces }}
|
||||||
{{- range $_, $i := $p.IssueRefs -}}
|
{{- range $_, $i := $p.Item.IssueRefs -}}
|
||||||
<div>
|
<div>
|
||||||
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
|
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user