perf: убрано избыточное логирование при импорте для повышения производительности
- Удалено детальное логирование каждой строки импорта в PHP (error_log в циклах) - Убраны console.log при парсинге и обработке CSV на фронтенде - Оставлено только логирование начала/конца импорта и ошибок - Значительно улучшена производительность при импорте больших файлов (тысячи строк)
This commit is contained in:
@@ -170,23 +170,18 @@ $app->post('/api/table/delete', function (Request $request, Response $response)
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
});
|
||||
|
||||
// API: импорт CSV (массовая вставка)
|
||||
// API: импорт CSV (массовая вставка)
|
||||
$app->post('/api/table/import-csv', function (Request $request, Response $response) use ($container) {
|
||||
error_log("\n========== ЗАПРОС НА ИМПОРТ CSV ==========");
|
||||
|
||||
$body = (string)$request->getBody();
|
||||
error_log("Тело запроса (первые 1000 символов): " . substr($body, 0, 1000));
|
||||
|
||||
$payload = json_decode($body, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("ОШИБКА JSON: " . json_last_error_msg());
|
||||
error_log("CSV Import: Invalid JSON - " . json_last_error_msg());
|
||||
$response->getBody()->write(json_encode(['error' => 'Invalid JSON: ' . json_last_error_msg()]));
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
|
||||
}
|
||||
|
||||
error_log("Декодированный payload: " . json_encode($payload, JSON_PRETTY_PRINT));
|
||||
|
||||
$pdo = $container->get('db');
|
||||
$meta = new \App\MetaService($pdo);
|
||||
$ds = new \App\DataService($pdo);
|
||||
@@ -195,29 +190,20 @@ $app->post('/api/table/import-csv', function (Request $request, Response $respon
|
||||
$table = $payload['table'] ?? '';
|
||||
$rows = $payload['rows'] ?? [];
|
||||
|
||||
error_log("Schema: $schema");
|
||||
error_log("Table: $table");
|
||||
error_log("Количество строк: " . count($rows));
|
||||
|
||||
if (empty($schema) || empty($table)) {
|
||||
error_log("ОШИБКА: пустая schema или table");
|
||||
error_log("CSV Import: Missing schema or table");
|
||||
$response->getBody()->write(json_encode(['error' => 'Schema and table are required']));
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
$metaArr = $meta->getTableMeta($schema, $table);
|
||||
error_log("Метаданные таблицы получены, столбцов: " . count($metaArr['columns']));
|
||||
|
||||
$result = $ds->insertMultipleRows($schema, $table, $rows, $metaArr['columns']);
|
||||
|
||||
error_log("Результат импорта: " . json_encode($result));
|
||||
|
||||
$response->getBody()->write(json_encode($result));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
} catch (\Exception $e) {
|
||||
error_log("КРИТИЧЕСКАЯ ОШИБКА: " . $e->getMessage());
|
||||
error_log("Stack trace: " . $e->getTraceAsString());
|
||||
error_log("CSV Import: Critical error - " . $e->getMessage());
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'error' => $e->getMessage(),
|
||||
|
||||
Reference in New Issue
Block a user