From dbcbef97aad98c9389bc41c73c2b2e38ebdc0289 Mon Sep 17 00:00:00 2001 From: Sasha Blashenkov Date: Wed, 28 Feb 2024 17:29:56 +0100 Subject: [PATCH] [feature-usage-database] even less logging GitOrigin-RevId: bf5c59211b4dc18d2b843a6a1373580ec523e96f --- .../core/dbs/SqliteLazyInitializedDatabase.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/feature-usage-database/core/src/com/intellij/ae/database/core/dbs/SqliteLazyInitializedDatabase.kt b/plugins/feature-usage-database/core/src/com/intellij/ae/database/core/dbs/SqliteLazyInitializedDatabase.kt index deef47d1b6ae..9eaf60c4cb50 100644 --- a/plugins/feature-usage-database/core/src/com/intellij/ae/database/core/dbs/SqliteLazyInitializedDatabase.kt +++ b/plugins/feature-usage-database/core/src/com/intellij/ae/database/core/dbs/SqliteLazyInitializedDatabase.kt @@ -95,7 +95,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe try { withTimeout(timeout) { withContext(closeDispatcher) { - closeDatabaseImpl(isFinal)?.join() + closeDatabaseImpl(isFinal, shouldLog)?.join() if (shouldLog) { logger.info("Saving completed (reason: $reason)") } @@ -133,7 +133,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe } @Suppress("OPT_IN_USAGE") - private fun closeDatabaseImpl(isFinal: Boolean): Job? { + private fun closeDatabaseImpl(isFinal: Boolean, shouldLog: Boolean): Job? { // service scope is dead at this point, need to use GlobalScope // todo: not true on temp close fun launchJob(action: suspend CoroutineScope.() -> Unit): Job = @@ -148,7 +148,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe val connection = getConn2(this) if (connection != null) { logger.info("Connection opened, performing termination.") - close(connection, isFinal = true) + close(connection, isFinal = true, shouldLog = shouldLog) } else { logger.info("Connection open failure.") } @@ -156,7 +156,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe } is State.Active -> { val job = launchJob { - close(state.def.await(), isFinal) + close(state.def.await(), isFinal, shouldLog = shouldLog) } val newState = State.Cancelling(state.def, job) if (myConnection.compareAndSet(state, newState)) { @@ -249,13 +249,17 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe } } - private suspend fun close(connectionHolder: ConnectionHolder, isFinal: Boolean) { - logger.info("close start") + private suspend fun close(connectionHolder: ConnectionHolder, isFinal: Boolean, shouldLog: Boolean) { + if (shouldLog) { + logger.info("close start") + } connectionHolder.connection.use { doExecuteBeforeConnectionClosed(isFinal) } check(connectionHolder.connection.isClosed) - logger.info("close end") + if (shouldLog) { + logger.info("close end") + } } private fun createDatabasePath(): Path? {