fun cleanup()

in src/main/kotlin/org/jetbrains/teamcity/github/WebhookPeriodicalChecker.kt [303:320]


        fun cleanup() {
            if (!TeamCityProperties.getBooleanOrTrue("teamcity.githubWebhooks.cleanupAuthData")) return

            val unused = myLastCheckUnusedData
            val currentTime = System.currentTimeMillis()
            if (unused == null || currentTime - myLastCheckTimestamp > TimeUnit.MINUTES.toMillis(25)) {
                val usedPublicKeys = myWebHooksStorage.getAll()
                        .mapNotNull { GitHubWebHookListener.getPubKeyFromRequestPath(it.second.callbackUrl) }.toHashSet()
                if (unused != null) {
                    myAuthDataStorage.remove(unused.filter { !usedPublicKeys.contains(it.public) })
                }
                myLastCheckUnusedData = myAuthDataStorage.getAll().filter {
                    !usedPublicKeys.contains(it.public)
                    && (it.repository != null || TeamCityProperties.getBoolean("teamcity.githubWebhooks.cleanupAuthData.withoutRepository"))
                }
                myLastCheckTimestamp = currentTime
            }
        }