From d799a2127780a3666d93f080ad7020b71cd5e832 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Wed, 7 Sep 2022 00:40:31 +0200 Subject: [PATCH] Add voting cache to lessen spam --- .../java/com/lagradost/cloudstream3/plugins/VotingApi.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/VotingApi.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/VotingApi.kt index 0a7057e5..7b9dc8c7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/VotingApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/VotingApi.kt @@ -37,10 +37,15 @@ object VotingApi { // please do not cheat the votes lol return getVoteType(url) } + // Plugin url to Int + private val votesCache = mutableMapOf() + suspend fun getVotes(pluginUrl: String): Int { val url = "${apiDomain}/get/cs3-votes/${transformUrl(pluginUrl)}" Log.d(LOGKEY, "Requesting: $url") - return app.get(url).parsedSafe()?.value ?: (0.also { + return votesCache[pluginUrl] ?: app.get(url).parsedSafe()?.value?.also { + votesCache[pluginUrl] = it + } ?: (0.also { ioSafe { createBucket(pluginUrl) } @@ -74,6 +79,7 @@ object VotingApi { // please do not cheat the votes lol val res = app.get(url).parsedSafe()?.value if (res != null) { setKey("cs3-votes/${transformUrl(pluginUrl)}", newType) + votesCache[pluginUrl] = res } return res ?: 0 }