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,10 +2,13 @@ package db
import (
"context"
"database/sql"
"errors"
"fmt"
"time"
"github.com/jmoiron/sqlx"
"golang.org/x/sync/errgroup"
)
type World struct {
@@ -53,28 +56,31 @@ func (w *World) Query(data *InsertId[string]) {
}
func (w *World) InsertObjects(tx *sqlx.Tx) error {
relId := &InsertId[string]{id: w.ID, fieldName: "world_id"}
syncDB := NewSyncDB()
defer close(syncDB.errChan)
relId := InsertId[string]{id: w.ID, fieldName: "world_id"}
group, ctx := errgroup.WithContext(context.Background())
InsertWithCtxParallel(syncDB, tx, w.Compatibility, relId)
InsertWithCtxParallel(syncDB, tx, w.Relationships, relId)
InsertWithCtxParallel(group, ctx, tx, w.Compatibility, relId)
InsertWithCtxParallel(group, ctx, tx, w.Relationships, relId)
esModulesRelId := &InsertId[string]{id: w.ID, fieldName: "world_id", tableName: "es_modules"}
InsertSimpleSliceParallel(syncDB, tx, w.Esmodules, esModulesRelId)
InsertSimpleSliceParallel(group, tx, w.Esmodules, esModulesRelId)
scriptRelId := &InsertId[string]{id: w.ID, fieldName: "world_id", tableName: "scripts"}
InsertSimpleSliceParallel(syncDB, tx, w.Scripts, scriptRelId)
InsertSimpleSliceParallel(group, tx, w.Scripts, scriptRelId)
tagsRelId := &InsertId[string]{id: w.ID, fieldName: "world_id", tableName: "tags"}
InsertSimpleSliceParallel(syncDB, tx, w.Tags, tagsRelId)
InsertSimpleSliceParallel(group, tx, w.Tags, tagsRelId)
InsertSliceParallel(syncDB, tx, w.Authors, relId)
InsertSliceParallel(syncDB, tx, w.Media, relId)
InsertSliceParallel(syncDB, tx, w.Styles, relId)
InsertSliceParallel(syncDB, tx, w.Languages, relId)
InsertSliceParallel(syncDB, tx, w.Packs, relId)
InsertSliceParallel(syncDB, tx, w.PackFolders, relId)
InsertSliceParallel(group, tx, w.Authors, relId)
InsertSliceParallel(group, tx, w.Media, relId)
InsertSliceParallel(group, tx, w.Styles, relId)
InsertSliceParallel(group, tx, w.Languages, relId)
InsertSliceParallel(group, tx, w.Packs, relId)
InsertSliceParallel(group, tx, w.PackFolders, relId)
return syncDB.Wait()
err := group.Wait()
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return nil
}
func (w *World) Insert(tx *sqlx.Tx, data *InsertId[string]) error {