mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25:32 +00:00
Speed up data insertion
This commit is contained in:
@@ -16,7 +16,11 @@ import (
|
||||
|
||||
const NO_TITLE = "[No Title]"
|
||||
|
||||
func RecordsFromInhalte(app core.App, inhalte xmlmodels.Inhalte) ([]*dbmodels.Content, error) {
|
||||
func RecordsFromInhalte(
|
||||
app core.App,
|
||||
inhalte xmlmodels.Inhalte,
|
||||
entries map[string]*dbmodels.Entry,
|
||||
) ([]*dbmodels.Content, error) {
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.CONTENTS_TABLE)
|
||||
records := make([]*dbmodels.Content, 0, len(inhalte.Inhalte))
|
||||
if err != nil {
|
||||
@@ -29,11 +33,7 @@ func RecordsFromInhalte(app core.App, inhalte xmlmodels.Inhalte) ([]*dbmodels.Co
|
||||
for i := 0; i < len(inhalte.Inhalte); i++ {
|
||||
record := dbmodels.NewContent(core.NewRecord(collection))
|
||||
inhalt := inhalte.Inhalte[i]
|
||||
band, err := app.FindFirstRecordByData(dbmodels.ENTRIES_TABLE, dbmodels.MUSENALMID_FIELD, inhalt.Band)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error finding band record for inhalt", "error", err, "inhalt", inhalt)
|
||||
continue
|
||||
}
|
||||
band, ok := entries[inhalt.Band]
|
||||
|
||||
record.SetEntry(band.Id)
|
||||
record.SetAnnotation(NormalizeString(inhalt.Anmerkungen))
|
||||
|
||||
@@ -9,7 +9,12 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func RecordsFromRelationInhalteAkteure(app core.App, relations xmlmodels.Relationen_Inhalte_Akteure) ([]*dbmodels.RContentsAgents, error) {
|
||||
func RecordsFromRelationInhalteAkteure(
|
||||
app core.App,
|
||||
relations xmlmodels.Relationen_Inhalte_Akteure,
|
||||
contents map[string]*dbmodels.Content,
|
||||
agents map[string]*dbmodels.Agent,
|
||||
) ([]*dbmodels.RContentsAgents, error) {
|
||||
records := make([]*dbmodels.RContentsAgents, 0, len(relations.Relationen))
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.CONTENTS_TABLE, dbmodels.AGENTS_TABLE))
|
||||
if err != nil {
|
||||
@@ -18,19 +23,17 @@ func RecordsFromRelationInhalteAkteure(app core.App, relations xmlmodels.Relatio
|
||||
}
|
||||
|
||||
for _, relation := range relations.Relationen {
|
||||
c, err := app.FindFirstRecordByData(dbmodels.CONTENTS_TABLE, dbmodels.MUSENALMID_FIELD, relation.Inhalt)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error finding Inhalt", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
content := dbmodels.NewContent(c)
|
||||
|
||||
a, err := app.FindFirstRecordByData(dbmodels.AGENTS_TABLE, dbmodels.MUSENALMID_FIELD, relation.Akteur)
|
||||
if err != nil {
|
||||
content, ok := contents[relation.Inhalt]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Content", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
agent := dbmodels.NewAgent(a)
|
||||
|
||||
agent, ok := agents[relation.Akteur]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Agent", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
|
||||
record := dbmodels.NewRContentsAgents(core.NewRecord(collection))
|
||||
record.SetContent(content.Id)
|
||||
|
||||
@@ -8,7 +8,12 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func RecordsFromRelationBändeAkteure(app core.App, relations xmlmodels.Relationen_Bände_Akteure) ([]*dbmodels.REntriesAgents, error) {
|
||||
func RecordsFromRelationBändeAkteure(
|
||||
app core.App,
|
||||
relations xmlmodels.Relationen_Bände_Akteure,
|
||||
entries map[string]*dbmodels.Entry,
|
||||
agents map[string]*dbmodels.Agent,
|
||||
) ([]*dbmodels.REntriesAgents, error) {
|
||||
records := make([]*dbmodels.REntriesAgents, 0, len(relations.Relationen))
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.AGENTS_TABLE))
|
||||
if err != nil {
|
||||
@@ -17,14 +22,14 @@ func RecordsFromRelationBändeAkteure(app core.App, relations xmlmodels.Relation
|
||||
}
|
||||
|
||||
for _, relation := range relations.Relationen {
|
||||
entry, err := app.FindFirstRecordByData(dbmodels.ENTRIES_TABLE, dbmodels.MUSENALMID_FIELD, relation.Band)
|
||||
if err != nil {
|
||||
entry, ok := entries[relation.Band]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Entry", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
|
||||
agent, err := app.FindFirstRecordByData(dbmodels.AGENTS_TABLE, dbmodels.MUSENALMID_FIELD, relation.Akteur)
|
||||
if err != nil {
|
||||
agent, ok := agents[relation.Akteur]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Agent", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
@@ -49,9 +54,8 @@ func RecordsFromRelationBändeAkteure(app core.App, relations xmlmodels.Relation
|
||||
ser := record.Agent()
|
||||
|
||||
if strings.TrimSpace(rel) == "" || strings.TrimSpace(ent) == "" || strings.TrimSpace(ser) == "" {
|
||||
e := dbmodels.NewEntry(entry)
|
||||
e.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
|
||||
_ = app.Save(e)
|
||||
entry.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
|
||||
_ = app.Save(entry)
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,12 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func RecordsFromRelationBändeReihen(app core.App, relations xmlmodels.Relationen_Bände_Reihen) ([]*dbmodels.REntriesSeries, error) {
|
||||
func RecordsFromRelationBändeReihen(
|
||||
app core.App,
|
||||
relations xmlmodels.Relationen_Bände_Reihen,
|
||||
series map[string]*dbmodels.Series,
|
||||
entries map[string]*dbmodels.Entry,
|
||||
) ([]*dbmodels.REntriesSeries, error) {
|
||||
records := make([]*dbmodels.REntriesSeries, 0, len(relations.Relationen))
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE))
|
||||
if err != nil {
|
||||
@@ -17,16 +22,14 @@ func RecordsFromRelationBändeReihen(app core.App, relations xmlmodels.Relatione
|
||||
}
|
||||
|
||||
for _, relation := range relations.Relationen {
|
||||
e, err := app.FindFirstRecordByData(dbmodels.ENTRIES_TABLE, dbmodels.MUSENALMID_FIELD, relation.Band)
|
||||
if err != nil {
|
||||
entry, ok := entries[relation.Band]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Entry", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
|
||||
entry := dbmodels.NewEntry(e)
|
||||
|
||||
series, err := app.FindFirstRecordByData(dbmodels.SERIES_TABLE, dbmodels.MUSENALMID_FIELD, relation.Reihe)
|
||||
if err != nil {
|
||||
series, ok := series[relation.Reihe]
|
||||
if !ok {
|
||||
app.Logger().Error("Error finding Series", "error", err, "relation", relation)
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user