diff --git a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/DltAnalyzerWindow.kt b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/DltAnalyzerWindow.kt index ab6920e..c782d1f 100644 --- a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/DltAnalyzerWindow.kt +++ b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/DltAnalyzerWindow.kt @@ -90,12 +90,8 @@ class DltAnalyzerWindow { ) { progress -> if (progress.progress != null) { SwingUtilities.invokeLater { - if (progress.progress != null) { - progressBar.isIndeterminate = false - progressBar.value = (progress.progress!! * 100f).roundToInt() - } else { - progressBar.isIndeterminate = true - } + progressBar.isIndeterminate = false + progressBar.value = (progress.progress!! * 100f).roundToInt() progressBar.string = progress.progressText } } else if (!progressBar.isIndeterminate) { diff --git a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/sxs/LogPanel.kt b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/sxs/LogPanel.kt index 8789fad..e559692 100644 --- a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/sxs/LogPanel.kt +++ b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/sxs/LogPanel.kt @@ -4,7 +4,6 @@ import analyzer.asIcon import analyzer.formatDefault import analyzer.plugin.DltTargetAware import db.DltLog -import db.DltTableDataAccess import db.DltTarget import jiconfont.icons.google_material_design_icons.GoogleMaterialDesignIcons import org.ktorm.dsl.inList @@ -45,6 +44,7 @@ class LogPanel : JPanel(BorderLayout()), DltTargetAware { logger.info("Updating Text") if (this.appId != appId || force) { thread(isDaemon = true) { + val dltTarget = this.dltTarget if (dltTarget == null) { SwingUtilities.invokeLater { textArea.text = "No dlt target is selected" @@ -52,9 +52,9 @@ class LogPanel : JPanel(BorderLayout()), DltTargetAware { return@thread } textArea.text = "Loading data" - val dao = DltTableDataAccess(dltTarget!!.dataSource) + val appIds = appId.split(',', ' ', ';').filter { it.isNotBlank() } - val data = dao.readData(listOf(DltLog.appId.inList(appIds))) + val data = dltTarget.dataAccess.readData(listOf(DltLog.appId.inList(appIds))) val text = data.joinToString("\n") { if (appIds.size > 1) { "[${it.timestamp.formatDefault()} ${it.appId.padEnd(4, ' ')} ${it.messageType.shortText.padEnd(5, ' ')}] ${it.message.trimEnd()}" diff --git a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/table/DltTableModel.kt b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/table/DltTableModel.kt index a089c5e..513aacb 100644 --- a/dlt-analyzer-app/src/main/kotlin/analyzer/ui/table/DltTableModel.kt +++ b/dlt-analyzer-app/src/main/kotlin/analyzer/ui/table/DltTableModel.kt @@ -36,7 +36,7 @@ class DltTableModel(private var dltTarget: DltTarget, private var internalFilter private val CACHED_ENTRIES_COUNT = 1_000 - private var tableAccess: DltTableDataAccess + private var tableAccess: DltTableDataAccess = dltTarget.dataAccess private var rowCount: Int = 0 private var listOffset = 0 @@ -44,7 +44,6 @@ class DltTableModel(private var dltTarget: DltTarget, private var internalFilter private var cachedEntriesColor: MutableMap = mutableMapOf() init { - tableAccess = DltTableDataAccess(dltTarget.dataSource) rowCount = tableAccess.getEntryCount(filterList.sqlWhere()).toInt() } diff --git a/dlt-database/src/main/kotlin/db/DltManager.kt b/dlt-database/src/main/kotlin/db/DltManager.kt index f5f5110..23343b8 100644 --- a/dlt-database/src/main/kotlin/db/DltManager.kt +++ b/dlt-database/src/main/kotlin/db/DltManager.kt @@ -53,9 +53,9 @@ object DltManager { if (reuseExisting) { logger.info("Reusing existing database file ${dbFile.absolutePath}") + dataAccess.createIndexes() } - if (!reuseExisting) { dataAccess.initialize() } @@ -120,4 +120,6 @@ data class DltTarget( val dltFile: File?, val dataSource: DataSource, var isLoaded: Boolean = false, -) +) { + val dataAccess by lazy { DltTableDataAccess(dataSource) } +} diff --git a/dlt-database/src/main/kotlin/db/DltTableDataAccess.kt b/dlt-database/src/main/kotlin/db/DltTableDataAccess.kt index 94715ff..b17d6c2 100644 --- a/dlt-database/src/main/kotlin/db/DltTableDataAccess.kt +++ b/dlt-database/src/main/kotlin/db/DltTableDataAccess.kt @@ -73,17 +73,15 @@ class DltTableDataAccess(private val dataSource: DataSource) { limit: Int? = null ): List { val list = mutableListOf() - val duration = measureTimeMillis { - database - .from(DltLog) - .select() - .whereWithOrConditions { list -> list.addAll(sqlClausesOr) } - .orderBy(DltLog.id.asc()) - .limit(offset, limit) - .mapTo(list) { row -> DltLog.createEntity(row) } - } - logger.debug("Reading data for took $duration ms") + database + .from(DltLog) + .select() + .whereWithOrConditions { list -> list.addAll(sqlClausesOr) } + .orderBy(DltLog.id.asc()) + .limit(offset, limit) + .mapTo(list) { row -> DltLog.createEntity(row) } + return list } @@ -94,8 +92,6 @@ class DltTableDataAccess(private val dataSource: DataSource) { .select(count(DltLog.id)) .whereWithOrConditions { list -> list.addAll(sqlClausesOr) } - logger.info("Retrieving count ${sql.sql}") - return database.executeQuery(sql.expression).use { it.first() it.getLong(1)