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 Module struct {
@@ -55,29 +58,32 @@ func (m *Module) Query(data *InsertId[uint]) {
}
func (m *Module) InsertObjects(tx *sqlx.Tx) error {
relId := &InsertId[string]{id: m.ID, fieldName: "module_id"}
syncDB := NewSyncDB()
defer close(syncDB.errChan)
relId := InsertId[string]{id: m.ID, fieldName: "module_id"}
group, ctx := errgroup.WithContext(context.Background())
go InsertWithCtxParallel(syncDB, tx, m.DocumentTypes, relId)
go InsertWithCtxParallel(syncDB, tx, m.Relationships, relId)
go InsertWithCtxParallel(syncDB, tx, m.Compatibility, relId)
InsertWithCtxParallel(group, ctx, tx, m.DocumentTypes, relId)
InsertWithCtxParallel(group, ctx, tx, m.Relationships, relId)
InsertWithCtxParallel(group, ctx, tx, m.Compatibility, relId)
scriptRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "scripts"}
go InsertSimpleSliceParallel(syncDB, tx, m.Scripts, scriptRelId)
esModulesRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "es_modules"}
go InsertSimpleSliceParallel(syncDB, tx, m.Esmodules, esModulesRelId)
tagsRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "tags"}
go InsertSimpleSliceParallel(syncDB, tx, m.Tags, tagsRelId)
// scriptRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "scripts"}
// InsertSimpleSliceParallel(group, tx, m.Scripts, scriptRelId)
// esModulesRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "es_modules"}
// InsertSimpleSliceParallel(group, tx, m.Esmodules, esModulesRelId)
// tagsRelId := &InsertId[string]{id: m.ID, fieldName: "module_id", tableName: "tags"}
// InsertSimpleSliceParallel(group, tx, m.Tags, tagsRelId)
go InsertSliceParallel(syncDB, tx, m.Authors, relId)
go InsertSliceParallel(syncDB, tx, m.Media, relId)
go InsertSliceParallel(syncDB, tx, m.Styles, relId)
go InsertSliceParallel(syncDB, tx, m.Languages, relId)
go InsertSliceParallel(syncDB, tx, m.Packs, relId)
go InsertSliceParallel(syncDB, tx, m.PackFolders, relId)
// InsertSliceParallel(group, tx, m.Authors, relId)
// InsertSliceParallel(group, tx, m.Media, relId)
// InsertSliceParallel(group, tx, m.Styles, relId)
// InsertSliceParallel(group, tx, m.Languages, relId)
// InsertSliceParallel(group, tx, m.Packs, relId)
// InsertSliceParallel(group, tx, m.PackFolders, relId)
return syncDB.Wait()
err := group.Wait()
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return nil
}
func (m *Module) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {