Rename the retarded tables

This commit is contained in:
2026-01-06 16:54:14 +01:00
parent 810eaad04a
commit ba5dc88d8f
2 changed files with 22 additions and 22 deletions

View File

@@ -81,16 +81,16 @@ func (k *Killmail) FlattenKillmail() (*FlatKillmail, []*FlatModule) {
func (db *DBWrapper) SaveKillmails(killmails []Killmail) error {
ctx := context.Background()
// Prepare batch for flat_killmails
flatBatch, err := db.ch.PrepareBatch(ctx, "INSERT INTO flat_killmails")
// Prepare batch for killmails
flatBatch, err := db.ch.PrepareBatch(ctx, "INSERT INTO killmails")
if err != nil {
return fmt.Errorf("failed to prepare flat_killmails batch: %w", err)
return fmt.Errorf("failed to prepare killmails batch: %w", err)
}
// Prepare batch for fitted_modules
moduleBatch, err := db.ch.PrepareBatch(ctx, "INSERT INTO fitted_modules")
// Prepare batch for modules
moduleBatch, err := db.ch.PrepareBatch(ctx, "INSERT INTO modules")
if err != nil {
return fmt.Errorf("failed to prepare fitted_modules batch: %w", err)
return fmt.Errorf("failed to prepare modules batch: %w", err)
}
cyutils.Batched(killmails, 1000, func(batch []Killmail) {
@@ -122,13 +122,13 @@ func (db *DBWrapper) processBatch(ctx context.Context, batch []Killmail, flatBat
flatKM, modules := km.FlattenKillmail()
// Append to flat_killmails batch
// Append to killmails batch
err := flatBatch.Append(flatKM.Values()...)
if err != nil {
return err
}
// Append fitted modules to fitted_modules batch
// Append fitted modules to modules batch
for _, mod := range modules {
err = moduleBatch.Append(mod.Values()...)
if err != nil {
@@ -163,7 +163,7 @@ func (db *DBWrapper) checkExistingKillmails(ctx context.Context, killmailIDs []i
args[j] = id
}
query := fmt.Sprintf("SELECT killmail_id FROM flat_killmails WHERE killmail_id IN (%s)", strings.Join(placeholders, ","))
query := fmt.Sprintf("SELECT killmail_id FROM killmails WHERE killmail_id IN (%s)", strings.Join(placeholders, ","))
rows, err := db.ch.Query(ctx, query, args...)
if err != nil {
return nil, err

26
db.go
View File

@@ -107,9 +107,9 @@ func (db *DBWrapper) Init() error {
return fmt.Errorf("failed to migrate cache_entries table: %w", err)
}
// Create flat_killmails table
// Create killmails table
createFlatKillmails := `
CREATE TABLE IF NOT EXISTS flat_killmails (
CREATE TABLE IF NOT EXISTS killmails (
killmail_id Int64,
killmail_time DateTime,
solar_system_id Int64,
@@ -147,12 +147,12 @@ func (db *DBWrapper) Init() error {
PRIMARY KEY (killmail_id)`
err = db.ch.Exec(ctx, createFlatKillmails)
if err != nil {
return fmt.Errorf("failed to create flat_killmails table: %w", err)
return fmt.Errorf("failed to create killmails table: %w", err)
}
// Create fitted_modules table
// Create modules table
createFittedModules := `
CREATE TABLE IF NOT EXISTS fitted_modules (
CREATE TABLE IF NOT EXISTS modules (
killmail_id Int64,
item_type_id Int64,
slot String
@@ -161,7 +161,7 @@ func (db *DBWrapper) Init() error {
PRIMARY KEY (killmail_id, item_type_id)`
err = db.ch.Exec(ctx, createFittedModules)
if err != nil {
return fmt.Errorf("failed to create fitted_modules table: %w", err)
return fmt.Errorf("failed to create modules table: %w", err)
}
return nil
@@ -188,7 +188,7 @@ func (db *DBWrapper) QueryFits(params QueryParams) (*FitStatistics, error) {
fk.killmail_id,
fk.solar_system_id,
fk.victim_ship_type_id
FROM flat_killmails fk`
FROM killmails fk`
args := []interface{}{}
whereClauses := []string{}
@@ -208,7 +208,7 @@ func (db *DBWrapper) QueryFits(params QueryParams) (*FitStatistics, error) {
whereClauses = append(whereClauses, "fk.solar_system_id IN ("+strings.Join(placeholders, ",")+")")
}
// For module filters, we need to join with fitted_modules
// For module filters, we need to join with modules
var moduleJoin string
if len(modules) > 0 {
placeholders := make([]string, len(modules))
@@ -217,7 +217,7 @@ func (db *DBWrapper) QueryFits(params QueryParams) (*FitStatistics, error) {
args = append(args, modules[i])
}
moduleJoin = `
INNER JOIN fitted_modules fm ON fk.killmail_id = fm.killmail_id`
INNER JOIN modules fm ON fk.killmail_id = fm.killmail_id`
whereClauses = append(whereClauses, "fm.item_type_id IN ("+strings.Join(placeholders, ",")+")")
}
@@ -419,7 +419,7 @@ func (db *DBWrapper) calculateStats(params QueryParams, shipTypeIDs []int64, kil
// placeholders[i] = "?"
// args = append(args, killmailIDs[i])
// }
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM fitted_modules WHERE killmail_id IN (" + strings.Join(placeholders, ",") + ")"
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM modules WHERE killmail_id IN (" + strings.Join(placeholders, ",") + ")"
// } else {
// var shipPlaceholders []string
// if len(shipTypeIDs) > 0 {
@@ -434,9 +434,9 @@ func (db *DBWrapper) calculateStats(params QueryParams, shipTypeIDs []int64, kil
// }
// if len(shipPlaceholders) > 0 {
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM fitted_modules WHERE victim_ship_type_id IN (" + strings.Join(shipPlaceholders, ",") + ")"
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM modules WHERE victim_ship_type_id IN (" + strings.Join(shipPlaceholders, ",") + ")"
// } else {
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM fitted_modules"
// query = "SELECT item_type_id, flag, count(DISTINCT killmail_id) as count FROM modules"
// }
// if len(params.Systems) > 0 {
@@ -659,7 +659,7 @@ func (db *DBWrapper) calculateModuleStats(killmailIDs []int64, stats *FitStatist
fm.item_type_id,
fm.slot,
COUNT(DISTINCT fm.killmail_id) as count
FROM fitted_modules fm
FROM modules fm
WHERE fm.killmail_id IN (%s)
GROUP BY fm.item_type_id, fm.slot
ORDER BY count DESC`, strings.Join(placeholders, ","))