4.0.4: Оптимизация SQL и отладка
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m14s

This commit is contained in:
poignatov
2026-01-26 18:17:56 +03:00
parent 99156d578a
commit 6bea094b7f
5 changed files with 32 additions and 15 deletions

View File

@@ -6515,22 +6515,16 @@ func (a *App) getTaskDetailHandler(w http.ResponseWriter, r *http.Request) {
// Загружаем все награды всех подзадач одним запросом
if len(subtaskIDs) > 0 {
placeholders := make([]string, len(subtaskIDs))
args := make([]interface{}, len(subtaskIDs))
for i, id := range subtaskIDs {
placeholders[i] = fmt.Sprintf("$%d", i+1)
args[i] = id
}
query := fmt.Sprintf(`
// Используем параметризованный запрос с ANY(ARRAY[...])
query := `
SELECT rc.task_id, rc.id, rc.position, p.name AS project_name, rc.value, rc.use_progression
FROM reward_configs rc
JOIN projects p ON rc.project_id = p.id
WHERE rc.task_id = ANY(ARRAY[%s])
WHERE rc.task_id = ANY($1::int[])
ORDER BY rc.task_id, rc.position
`, strings.Join(placeholders, ","))
`
subtaskRewardRows, err := a.DB.Query(query, args...)
subtaskRewardRows, err := a.DB.Query(query, pq.Array(subtaskIDs))
if err != nil {
log.Printf("Error querying subtask rewards: %v", err)
} else {