IDs: string -> int

This commit is contained in:
Simon Martens
2025-02-19 22:03:40 +01:00
parent aa7c5f4d6c
commit 107a9d9f70
21 changed files with 94 additions and 63 deletions

View File

@@ -3,6 +3,7 @@ package seed
import (
"fmt"
"log"
"log/slog"
"os"
"path/filepath"
"strconv"
@@ -19,7 +20,7 @@ const NO_TITLE = "[No Title]"
func RecordsFromInhalte(
app core.App,
inhalte xmlmodels.Inhalte,
entries map[string]*dbmodels.Entry,
entries map[int]*dbmodels.Entry,
) ([]*dbmodels.Content, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.CONTENTS_TABLE)
records := make([]*dbmodels.Content, 0, len(inhalte.Inhalte))
@@ -127,9 +128,9 @@ func commatizeArray(array []string) string {
return array[0]
}
func getImages(path string) map[string][]string {
func getImages(path string) map[int][]string {
/// FIXED: there is a bug somewhere, where files ending with numbers after a comma (",001") etc dont get added
ret := make(map[string][]string)
ret := make(map[int][]string)
if _, err := os.Stat(path); os.IsNotExist(err) {
return ret
}
@@ -142,10 +143,15 @@ func getImages(path string) map[string][]string {
if len(basesplit) >= 3 {
commaseperatorsplit := strings.Split(basesplit[2], ",")
id := commaseperatorsplit[0]
if _, ok := ret[id]; !ok {
ret[id] = make([]string, 0)
no, err := strconv.Atoi(id)
if err != nil {
slog.Error("Error parsing id", "error", err, "id", id)
return nil
}
ret[id] = append(ret[id], path)
if _, ok := ret[no]; !ok {
ret[no] = make([]string, 0)
}
ret[no] = append(ret[no], path)
}
}
return nil

View File

@@ -15,6 +15,7 @@ import (
func RecordsFromBände(
app core.App,
adb xmlmodels.AccessDB,
// INFO: this is a string map, bc it's not by ID but by place name
places map[string]*dbmodels.Place,
) ([]*dbmodels.Entry, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
@@ -31,12 +32,12 @@ func RecordsFromBände(
}
// INFO: lets make some maps to speed this up
omap := datatypes.MakeMap(adb.Orte.Orte, func(o xmlmodels.Ort) string { return o.ID })
omap := datatypes.MakeMap(adb.Orte.Orte, func(o xmlmodels.Ort) int { return o.ID })
relmap := datatypes.MakeMultiMap(
adb.Relationen_Bände_Reihen.Relationen,
func(r xmlmodels.Relation_Band_Reihe) string { return r.Band },
func(r xmlmodels.Relation_Band_Reihe) int { return r.Band },
)
rmap := datatypes.MakeMap(adb.Reihen.Reihen, func(r xmlmodels.Reihe) string { return r.ID })
rmap := datatypes.MakeMap(adb.Reihen.Reihen, func(r xmlmodels.Reihe) int { return r.ID })
for i := 0; i < len(adb.Bände.Bände); i++ {
band := adb.Bände.Bände[i]
@@ -86,8 +87,8 @@ func RecordsFromBände(
func handlePreferredTitleEntry(
record *dbmodels.Entry,
band xmlmodels.Band,
rmap map[string]xmlmodels.Reihe,
rrelmap map[string][]xmlmodels.Relation_Band_Reihe,
rmap map[int]xmlmodels.Reihe,
rrelmap map[int][]xmlmodels.Relation_Band_Reihe,
) {
rels := rrelmap[band.ID]
if len(rels) == 0 {
@@ -120,7 +121,7 @@ func handlePreferredTitleEntry(
func handleOrte(
record *dbmodels.Entry,
band xmlmodels.Band,
orte map[string]xmlmodels.Ort,
orte map[int]xmlmodels.Ort,
app core.App,
ocollection *core.Collection,
places map[string]*dbmodels.Place,

View File

@@ -16,7 +16,7 @@ func ItemsFromBändeAndBIBLIO(
app core.App,
entries xmlmodels.Bände,
biblio map[int]xmlmodels.BIBLIOEintrag,
entriesmap map[string]*dbmodels.Entry,
entriesmap map[int]*dbmodels.Entry,
) ([]*dbmodels.Item, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE)
records := make([]*dbmodels.Item, 0, len(entries.Bände))

View File

@@ -12,8 +12,8 @@ import (
func RecordsFromRelationInhalteAkteure(
app core.App,
relations xmlmodels.Relationen_Inhalte_Akteure,
contents map[string]*dbmodels.Content,
agents map[string]*dbmodels.Agent,
contents map[int]*dbmodels.Content,
agents map[int]*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))

View File

@@ -11,8 +11,8 @@ import (
func RecordsFromRelationBändeAkteure(
app core.App,
relations xmlmodels.Relationen_Bände_Akteure,
entries map[string]*dbmodels.Entry,
agents map[string]*dbmodels.Agent,
entries map[int]*dbmodels.Entry,
agents map[int]*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))

View File

@@ -11,8 +11,8 @@ import (
func RecordsFromRelationBändeReihen(
app core.App,
relations xmlmodels.Relationen_Bände_Reihen,
series map[string]*dbmodels.Series,
entries map[string]*dbmodels.Entry,
series map[int]*dbmodels.Series,
entries map[int]*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))