finish setup data insertion, add world insertion

This commit is contained in:
lbenedar
2026-04-22 18:18:43 +03:00
parent 21abe68858
commit f46ff8333e
66 changed files with 2257 additions and 676 deletions

View File

@@ -2,9 +2,12 @@ package db
import (
"context"
"database/sql"
"errors"
"fmt"
"github.com/jmoiron/sqlx"
"golang.org/x/sync/errgroup"
)
type System struct {
@@ -54,30 +57,33 @@ func (s *System) Query(data *InsertId[string]) {
}
func (s *System) InsertObjects(tx *sqlx.Tx) error {
relId := &InsertId[string]{id: s.ID, fieldName: "system_id"}
syncDB := NewSyncDB()
defer close(syncDB.errChan)
relId := InsertId[string]{id: s.ID, fieldName: "system_id"}
group, ctx := errgroup.WithContext(context.Background())
InsertWithCtxParallel(syncDB, tx, s.Compatibility, relId)
InsertWithCtxParallel(syncDB, tx, s.Relationships, relId)
InsertWithCtxParallel(syncDB, tx, s.DocumentTypes, relId)
InsertWithCtxParallel(syncDB, tx, s.Grid, relId)
InsertWithCtxParallel(group, ctx, tx, s.Compatibility, relId)
InsertWithCtxParallel(group, ctx, tx, s.Relationships, relId)
InsertWithCtxParallel(group, ctx, tx, s.DocumentTypes, relId)
InsertWithCtxParallel(group, ctx, tx, s.Grid, relId)
esModulesRelId := &InsertId[string]{id: s.ID, fieldName: "system_id", tableName: "es_modules"}
InsertSimpleSliceParallel(syncDB, tx, s.Esmodules, esModulesRelId)
InsertSimpleSliceParallel(group, tx, s.Esmodules, esModulesRelId)
scriptRelId := &InsertId[string]{id: s.ID, fieldName: "system_id", tableName: "scripts"}
InsertSimpleSliceParallel(syncDB, tx, s.Scripts, scriptRelId)
InsertSimpleSliceParallel(group, tx, s.Scripts, scriptRelId)
tagsRelId := &InsertId[string]{id: s.ID, fieldName: "system_id", tableName: "tags"}
InsertSimpleSliceParallel(syncDB, tx, s.Tags, tagsRelId)
InsertSimpleSliceParallel(group, tx, s.Tags, tagsRelId)
InsertSliceParallel(syncDB, tx, s.Authors, relId)
InsertSliceParallel(syncDB, tx, s.Media, relId)
InsertSliceParallel(syncDB, tx, s.Styles, relId)
InsertSliceParallel(syncDB, tx, s.Languages, relId)
InsertSliceParallel(syncDB, tx, s.Packs, relId)
InsertSliceParallel(syncDB, tx, s.PackFolders, relId)
InsertSliceParallel(group, tx, s.Authors, relId)
InsertSliceParallel(group, tx, s.Media, relId)
InsertSliceParallel(group, tx, s.Styles, relId)
InsertSliceParallel(group, tx, s.Languages, relId)
InsertSliceParallel(group, tx, s.Packs, relId)
InsertSliceParallel(group, tx, s.PackFolders, relId)
return syncDB.Wait()
err := group.Wait()
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return nil
}
func (s *System) Insert(tx *sqlx.Tx, data *InsertId[string]) error {