/
This commit is contained in:
@@ -78,36 +78,66 @@ public class MongoConfig {
|
||||
logger.debug("DocumentToMapConverter: Source is null, returning empty Map");
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
for (String key : source.keySet()) {
|
||||
Object value = source.get(key);
|
||||
// Рекурсивно конвертируем вложенные Document
|
||||
if (value instanceof Document) {
|
||||
logger.debug("DocumentToMapConverter: Found nested Document for key: {}", key);
|
||||
result.put(key, convert((Document) value));
|
||||
} else {
|
||||
result.put(key, value);
|
||||
}
|
||||
}
|
||||
logger.debug("DocumentToMapConverter: Successfully converted Document to Map with {} keys", result.size());
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
logger.debug("DocumentToMapConverter: Successfully converted Document to Map with {} keys. Duration: {} ms",
|
||||
result.size(), duration);
|
||||
|
||||
if (duration > 1000) {
|
||||
logger.warn("DocumentToMapConverter: Conversion took {} ms, which is longer than expected", duration);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Конвертер для записи: Map<String, Object> -> String
|
||||
* Не используется, но может быть полезен для обратной совместимости
|
||||
* Используется при сохранении reportData в MongoDB
|
||||
*/
|
||||
@WritingConverter
|
||||
public static class MapToStringConverter implements Converter<Map<String, Object>, String> {
|
||||
@Override
|
||||
public String convert(Map<String, Object> source) {
|
||||
logger.info("MapToStringConverter: Starting conversion of Map to String");
|
||||
if (source == null || source.isEmpty()) {
|
||||
logger.debug("MapToStringConverter: Source is null or empty, returning null");
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.debug("MapToStringConverter: Source Map size: {} keys. Keys: {}",
|
||||
source.size(), source.keySet());
|
||||
|
||||
try {
|
||||
return objectMapper.writeValueAsString(source);
|
||||
logger.debug("MapToStringConverter: Starting JSON serialization...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
String result = objectMapper.writeValueAsString(source);
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
logger.info(
|
||||
"MapToStringConverter: Successfully converted Map to String. Result length: {} chars, Duration: {} ms",
|
||||
result != null ? result.length() : 0, duration);
|
||||
|
||||
if (duration > 5000) {
|
||||
logger.warn("MapToStringConverter: Conversion took {} ms, which is longer than expected", duration);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error converting Map to String: {}", e.getMessage(), e);
|
||||
logger.error("MapToStringConverter: Error converting Map to String. Map size: {}, Keys: {}",
|
||||
source.size(), source.keySet(), e);
|
||||
logger.error("MapToStringConverter: Stack trace: ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,34 @@ public class MarketingAnalysisService {
|
||||
analysis.setCompletedAt(LocalDateTime.now());
|
||||
logger.debug("processAnalysis: Setting reportData. ReportData keys: {}",
|
||||
reportData != null ? reportData.keySet() : "null");
|
||||
|
||||
// Логируем размер reportData перед сохранением
|
||||
if (reportData != null) {
|
||||
try {
|
||||
int estimatedSize = estimateMapSize(reportData);
|
||||
logger.info("processAnalysis: reportData estimated size: ~{} KB. Keys: {}",
|
||||
estimatedSize / 1024, reportData.keySet());
|
||||
} catch (Exception e) {
|
||||
logger.warn("processAnalysis: Could not estimate reportData size: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
analysis.setReportData(reportData);
|
||||
analysis.setPdfFilename(filename);
|
||||
analysis.setPdfFilePath(filename);
|
||||
addStatusHistoryEntry(analysis, "completed", "Анализ успешно завершен");
|
||||
logger.info("processAnalysis: Saving analysis to MongoDB for ID: {}", analysisId);
|
||||
logger.info(
|
||||
"processAnalysis: About to save analysis to MongoDB for ID: {}. This may take time for large reportData...",
|
||||
analysisId);
|
||||
long saveStartTime = System.currentTimeMillis();
|
||||
repository.save(analysis);
|
||||
logger.info("processAnalysis: Analysis saved successfully to MongoDB for ID: {}", analysisId);
|
||||
long saveDuration = System.currentTimeMillis() - saveStartTime;
|
||||
logger.info("processAnalysis: Analysis saved successfully to MongoDB for ID: {}. Save duration: {} ms",
|
||||
analysisId, saveDuration);
|
||||
|
||||
if (saveDuration > 10000) {
|
||||
logger.warn("processAnalysis: Save operation took {} ms, which is longer than expected", saveDuration);
|
||||
}
|
||||
|
||||
logger.info("processAnalysis: Marketing analysis completed successfully for ID: {}", analysisId);
|
||||
|
||||
@@ -2597,4 +2618,22 @@ public class MarketingAnalysisService {
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Оценивает примерный размер Map в байтах для логирования
|
||||
*/
|
||||
private int estimateMapSize(Map<String, Object> map) {
|
||||
if (map == null) {
|
||||
return 0;
|
||||
}
|
||||
int size = 0;
|
||||
try {
|
||||
String json = objectMapper.writeValueAsString(map);
|
||||
size = json.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
||||
} catch (Exception e) {
|
||||
// Если не удалось сериализовать, используем приблизительную оценку
|
||||
size = map.size() * 100; // Примерно 100 байт на ключ
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user