Skip to content

Commit

Permalink
Exclude interaction endpoints from global rate-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 28, 2024
1 parent e99c5c5 commit ffd7503
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 5 additions & 4 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -6492,10 +6492,11 @@ public abstract interface class dev/kord/rest/route/ResponseMapper {

public abstract class dev/kord/rest/route/Route {
public static final field Companion Ldev/kord/rest/route/Route$Companion;
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Ldev/kord/rest/route/ResponseMapper;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Ldev/kord/rest/route/ResponseMapper;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Lkotlinx/serialization/DeserializationStrategy;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Lkotlinx/serialization/DeserializationStrategy;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Ldev/kord/rest/route/ResponseMapper;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Ldev/kord/rest/route/ResponseMapper;ZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Lkotlinx/serialization/DeserializationStrategy;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lio/ktor/http/HttpMethod;Ljava/lang/String;Lkotlinx/serialization/DeserializationStrategy;ZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getAffectedByGlobalRateLimit ()Z
public final fun getMapper ()Ldev/kord/rest/route/ResponseMapper;
public final fun getMethod ()Lio/ktor/http/HttpMethod;
public final fun getPath ()Ljava/lang/String;
Expand Down
2 changes: 2 additions & 0 deletions rest/api/rest.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -7211,6 +7211,8 @@ sealed class <#A: kotlin/Any?, #B: dev.kord.common.entity/Choice> dev.kord.rest.
}

sealed class <#A: kotlin/Any?> dev.kord.rest.route/Route { // dev.kord.rest.route/Route|null[0]
final val affectedByGlobalRateLimit // dev.kord.rest.route/Route.affectedByGlobalRateLimit|{}affectedByGlobalRateLimit[0]
final fun <get-affectedByGlobalRateLimit>(): kotlin/Boolean // dev.kord.rest.route/Route.affectedByGlobalRateLimit.<get-affectedByGlobalRateLimit>|<get-affectedByGlobalRateLimit>(){}[0]
final val mapper // dev.kord.rest.route/Route.mapper|{}mapper[0]
final fun <get-mapper>(): dev.kord.rest.route/ResponseMapper<#A> // dev.kord.rest.route/Route.mapper.<get-mapper>|<get-mapper>(){}[0]
final val method // dev.kord.rest.route/Route.method|{}method[0]
Expand Down
4 changes: 3 additions & 1 deletion rest/src/commonMain/kotlin/ratelimit/AbstractRateLimiter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public abstract class AbstractRateLimiter internal constructor(public val clock:
}

override suspend fun await(request: Request<*, *>): RequestToken {
globalSuspensionPoint.value.await()
if (request.route.affectedByGlobalRateLimit) {
globalSuspensionPoint.value.await()
}
val buckets = request.buckets
buckets.forEach { it.awaitAndLock() }

Expand Down
12 changes: 11 additions & 1 deletion rest/src/commonMain/kotlin/route/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed class Route<T>(
public val path: String,
public val mapper: ResponseMapper<T>,
public val requiresAuthorizationHeader: Boolean = true,
public val affectedByGlobalRateLimit: Boolean = true
) {

public companion object {
Expand Down Expand Up @@ -91,7 +92,8 @@ public sealed class Route<T>(
path: String,
strategy: DeserializationStrategy<T>,
requiresAuthorizationHeader: Boolean = true,
) : this(method, path, ValueJsonMapper(strategy), requiresAuthorizationHeader)
affectedByGlobalRateLimit: Boolean = true
) : this(method, path, ValueJsonMapper(strategy), requiresAuthorizationHeader, affectedByGlobalRateLimit)

override fun toString(): String = "Route(method:${method.value},path:$path,mapper:$mapper)"

Expand Down Expand Up @@ -990,6 +992,7 @@ public sealed class Route<T>(
"/interactions/$InteractionId/$InteractionToken/callback",
NoStrategy,
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object OriginalInteractionResponseGet :
Expand All @@ -998,6 +1001,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/@original",
DiscordMessage.serializer(),
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object OriginalInteractionResponseModify :
Expand All @@ -1006,6 +1010,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/@original",
DiscordMessage.serializer(),
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object OriginalInteractionResponseDelete :
Expand All @@ -1014,6 +1019,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/@original",
NoStrategy,
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object FollowupMessageCreate :
Expand All @@ -1022,6 +1028,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken",
DiscordMessage.serializer(),
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object FollowupMessageGet :
Expand All @@ -1030,6 +1037,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/$MessageId",
DiscordMessage.serializer(),
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object FollowupMessageModify :
Expand All @@ -1038,6 +1046,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/$MessageId",
DiscordMessage.serializer(),
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)

public object FollowupMessageDelete :
Expand All @@ -1046,6 +1055,7 @@ public sealed class Route<T>(
"/webhooks/$ApplicationId/$InteractionToken/messages/$MessageId",
NoStrategy,
requiresAuthorizationHeader = false,
affectedByGlobalRateLimit = false
)


Expand Down

0 comments on commit ffd7503

Please sign in to comment.