Resolve all the other type information
This commit is contained in:
@@ -30,6 +30,12 @@ FROM
|
||||
WHERE
|
||||
item_type_name = ''
|
||||
OR item_type_name IS NULL
|
||||
OR item_group_name = ''
|
||||
OR item_group_name IS NULL
|
||||
OR item_category_name = ''
|
||||
OR item_category_name IS NULL
|
||||
OR item_market_group_name = ''
|
||||
OR item_market_group_name IS NULL
|
||||
ORDER BY
|
||||
item_type_id
|
||||
`
|
||||
|
||||
@@ -28,14 +28,40 @@ func resolveItemType(ctx context.Context, chClient *clickhouse.ClickhouseClient,
|
||||
return fmt.Errorf("failed to get type %d from database: %w", id, err)
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(
|
||||
"ALTER TABLE zkill.killmail_items UPDATE item_type_name = '%s' WHERE item_type_id = %d",
|
||||
escapeString(invType.TypeName),
|
||||
id,
|
||||
)
|
||||
typeName := escapeString(invType.TypeName)
|
||||
|
||||
if err := chClient.Exec(ctx, query); err != nil {
|
||||
return fmt.Errorf("failed to update item_type_name for item_type_id %d: %w", id, err)
|
||||
invGroup, err := dbClient.GetGroup(ctx, invType.GroupID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get group %d for type %d: %w", invType.GroupID, id, err)
|
||||
}
|
||||
groupName := escapeString(invGroup.GroupName)
|
||||
|
||||
invCategory, err := dbClient.GetCategory(ctx, invGroup.CategoryID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get category %d for group %d: %w", invGroup.CategoryID, invType.GroupID, err)
|
||||
}
|
||||
categoryName := escapeString(invCategory.CategoryName)
|
||||
|
||||
invMarketGroup, err := dbClient.GetMarketGroup(ctx, invType.MarketGroupID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get market group %d for type %d: %w", invType.MarketGroupID, id, err)
|
||||
}
|
||||
marketGroupName := escapeString(invMarketGroup.MarketGroupName)
|
||||
|
||||
queries := []string{
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_items UPDATE item_type_name = '%s' WHERE item_type_id = %d", typeName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmails UPDATE victim_ship_type_name = '%s' WHERE victim_ship_type_id = %d", typeName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_attackers UPDATE ship_type_name = '%s' WHERE ship_type_id = %d", typeName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_attackers UPDATE weapon_type_name = '%s' WHERE weapon_type_id = %d", typeName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_items UPDATE item_group_name = '%s' WHERE item_type_id = %d", groupName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_items UPDATE item_category_name = '%s' WHERE item_type_id = %d", categoryName, id),
|
||||
fmt.Sprintf("ALTER TABLE zkill.killmail_items UPDATE item_market_group_name = '%s' WHERE item_type_id = %d", marketGroupName, id),
|
||||
}
|
||||
|
||||
for _, query := range queries {
|
||||
if err := chClient.Exec(ctx, query); err != nil {
|
||||
return fmt.Errorf("failed to update type name for type_id %d: %w", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -35,7 +35,7 @@ func Run(topic, channel string, resolveId func(context.Context, *clickhouse.Clic
|
||||
handler := &NSQHandler{
|
||||
chClient: chClient,
|
||||
dbClient: dbClient,
|
||||
resolveId: resolveId,
|
||||
resolveID: resolveId,
|
||||
}
|
||||
|
||||
consumer, err := lnsq.ConnectToNSQ(topic, channel, handler)
|
||||
@@ -52,7 +52,7 @@ func Run(topic, channel string, resolveId func(context.Context, *clickhouse.Clic
|
||||
type NSQHandler struct {
|
||||
chClient *clickhouse.ClickhouseClient
|
||||
dbClient db.DB
|
||||
resolveId func(context.Context, *clickhouse.ClickhouseClient, db.DB, int64) error
|
||||
resolveID func(context.Context, *clickhouse.ClickhouseClient, db.DB, int64) error
|
||||
}
|
||||
|
||||
func (h *NSQHandler) HandleMessage(message *nsq.Message) error {
|
||||
@@ -63,7 +63,7 @@ func (h *NSQHandler) HandleMessage(message *nsq.Message) error {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
if err := h.resolveId(ctx, h.chClient, h.dbClient, id); err != nil {
|
||||
if err := h.resolveID(ctx, h.chClient, h.dbClient, id); err != nil {
|
||||
logger.Error("Failed to resolve ID %d: %v", id, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user