mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-07 21:37:02 +09:00
DROID-1567 App | Tech | Tracing subscriptions (#235)
This commit is contained in:
parent
b53ec846dd
commit
8abfb1d503
7 changed files with 71 additions and 4 deletions
|
@ -31,6 +31,8 @@ import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
|||
import com.anytypeio.anytype.domain.config.FeaturesConfigProvider
|
||||
import com.anytypeio.anytype.domain.config.InfrastructureRepository
|
||||
import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
||||
import com.anytypeio.anytype.domain.debugging.DebugConfig
|
||||
import com.anytypeio.anytype.domain.debugging.Logger
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
|
@ -196,10 +198,14 @@ object DataModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideBlockRepository(
|
||||
blockRemote: BlockRemote
|
||||
blockRemote: BlockRemote,
|
||||
debugConfig: DebugConfig,
|
||||
logger: Logger
|
||||
): BlockRepository {
|
||||
return BlockDataRepository(
|
||||
remote = blockRemote
|
||||
remote = blockRemote,
|
||||
debugConfig = debugConfig,
|
||||
logger = logger
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,13 @@ import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
|||
import com.anytypeio.anytype.core_utils.tools.ThreadInfo
|
||||
import com.anytypeio.anytype.core_utils.tools.UrlValidator
|
||||
import com.anytypeio.anytype.domain.config.Gateway
|
||||
import com.anytypeio.anytype.domain.debugging.DebugConfig
|
||||
import com.anytypeio.anytype.domain.debugging.Logger
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.middleware.interactor.MiddlewareProtobufLogger
|
||||
import com.anytypeio.anytype.middleware.interactor.ProtobufConverterProvider
|
||||
import com.anytypeio.anytype.other.BasicLogger
|
||||
import com.anytypeio.anytype.other.DefaultDebugConfig
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
@ -46,6 +50,14 @@ object UtilModule {
|
|||
@Module
|
||||
interface Bindings {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindLogger(logger: BasicLogger): Logger
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindDebugConfig(config: DefaultDebugConfig): DebugConfig
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindThreadInfo(info: DefaultThreadInfo): ThreadInfo
|
||||
|
|
15
app/src/main/java/com/anytypeio/anytype/other/BasicLogger.kt
Normal file
15
app/src/main/java/com/anytypeio/anytype/other/BasicLogger.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.anytypeio.anytype.other
|
||||
|
||||
import com.anytypeio.anytype.domain.debugging.Logger
|
||||
import javax.inject.Inject
|
||||
import timber.log.Timber
|
||||
|
||||
class BasicLogger @Inject constructor() : Logger {
|
||||
override fun logWarning(msg: String) {
|
||||
Timber.w(msg)
|
||||
}
|
||||
|
||||
override fun logException(e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.anytypeio.anytype.other
|
||||
|
||||
import com.anytypeio.anytype.BuildConfig
|
||||
import com.anytypeio.anytype.domain.debugging.DebugConfig
|
||||
import javax.inject.Inject
|
||||
|
||||
class DefaultDebugConfig @Inject constructor(): DebugConfig {
|
||||
override val traceSubscriptions: Boolean get() = BuildConfig.DEBUG
|
||||
}
|
|
@ -29,12 +29,16 @@ import com.anytypeio.anytype.data.auth.exception.UndoRedoExhaustedException
|
|||
import com.anytypeio.anytype.domain.base.Result
|
||||
import com.anytypeio.anytype.domain.block.interactor.sets.CreateObjectSet
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.debugging.DebugConfig
|
||||
import com.anytypeio.anytype.domain.debugging.Logger
|
||||
import com.anytypeio.anytype.domain.error.Error
|
||||
import com.anytypeio.anytype.domain.page.Redo
|
||||
import com.anytypeio.anytype.domain.page.Undo
|
||||
|
||||
class BlockDataRepository(
|
||||
private val remote: BlockRemote
|
||||
private val remote: BlockRemote,
|
||||
private val debugConfig: DebugConfig,
|
||||
private val logger: Logger
|
||||
) : BlockRepository {
|
||||
|
||||
override suspend fun openObject(id: Id): ObjectView = remote.openObject(id = id)
|
||||
|
@ -420,7 +424,17 @@ class BlockDataRepository(
|
|||
|
||||
override suspend fun cancelObjectSearchSubscription(
|
||||
subscriptions: List<Id>
|
||||
) = remote.cancelObjectSearchSubscription(subscriptions)
|
||||
) = remote.cancelObjectSearchSubscription(subscriptions).also {
|
||||
if (debugConfig.traceSubscriptions) {
|
||||
try {
|
||||
logger.logWarning(
|
||||
"Number of subscriptions after unsubscribe: ${remote.debugSubscriptions()}"
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logger.logException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun addRelationToObject(
|
||||
ctx: Id, relation: Id
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.anytypeio.anytype.domain.debugging
|
||||
|
||||
interface DebugConfig {
|
||||
val traceSubscriptions: Boolean
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.anytypeio.anytype.domain.debugging
|
||||
|
||||
interface Logger {
|
||||
fun logWarning(msg: String)
|
||||
fun logException(e: Exception)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue