Skip to content

Player Counter: make query rate limit configurable - #180

Open
impaex wants to merge 2 commits into
pelican:mainfrom
impaex:player-counter/query-rate-limit
Open

impaex wants to merge 2 commits into
pelican:mainfrom
impaex:player-counter/query-rate-limit

Conversation

@impaex

@impaex impaex commented Nov 15, 2026 •

Copy link
Copy Markdown

Feature Description

This PR makes the rate limit for the Player Counter query endpoints configurable in the plugin settings. It was hardcoded to 2 requests per minute per server.

The reason for this change is that I am relying on this plugin for retrieving player lists from my own hosted servers, to display on my website and Discord server. Since they're my own, I would like to query them every 15 seconds, which exceeded the original rate limits.

What's new:

  • New setting "Query rate limit" (integer, minimum 0), saved as PLAYER_COUNTER_QUERY_RATE_LIMIT
  • Default stays at 2, so existing installs behave the same
  • 0 disables the plugin's limit. The panel-wide client API rate limit however still applies
  • Negative values set directly in .env are treated as 1

The limit still covers /api/client/servers/{uuid}/query and /query/players with one shared bucket per server. My use case has no interest in splitting these up into separate buckets, but could be a logical next step.

What has been tested

I've tested the following things to make sure it works:

  • Settings field loads with the current value and saves to .env
  • With the limit at 5: five requests pass, the sixth returns 429
  • Without the env key: two requests pass, the third returns 429
  • PLAYER_COUNTER_QUERY_RATE_LIMIT=0: 10 requests in a row without a 429
  • PLAYER_COUNTER_QUERY_RATE_LIMIT=-3 results in a limit of 1
  • Pint and PHPStan pass

AI usage

The German and Russian translations of the three new strings were generated with AI (Claude Fable 5.2) to make sure the translations are more contextual than e.g. Google Translate. The translations have not been reviewed by a native speaker however. Corrections are welcome, or I can drop them and leave only the English strings.

Summary by CodeRabbit

  • New Features
    • Added a configurable per-server rate limit for query requests, set to two requests per minute by default. Both query endpoints share this limit.
    • You can adjust the limit in the player counter settings. Set it to 0 to disable the per-server limit; the panel-wide API limit continues to apply.
    • Settings labels and guidance are available in English, German, and Russian.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The player-counter plugin now exposes a configurable per-server query rate limit. The setting defaults to 2 requests per minute. A value of 0 disables this limiter, while the panel-wide Client API limit continues to apply.

Changes: Query rate limit

Layer / File(s) Summary
Configure the query rate limit
player-counter/config/player-counter.php, player-counter/src/PlayerCounterPlugin.php, player-counter/lang/*/query.php
The settings form adds a required integer field with a minimum of 0 and saves its value to PLAYER_COUNTER_QUERY_API_RATE_LIMIT. Configuration reads this value and defaults to 2. English, German, and Russian translations describe the setting.
Apply the per-server query limit
player-counter/src/Providers/PlayerCounterRoutesProvider.php
The limiter uses the configured value for requests keyed by server UUID. A value of 0 disables this limiter; other values allow at least one request per minute.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Feature

Suggested reviewers: boy132

Merge Risk: Minimal · up to 06d72

This adds a configurable per-server query rate limit that defaults to the previous value of 2 per minute. I found no concrete defect in the change. The PR description names a different environment key than the code uses, so documentation should use PLAYER_COUNTER_QUERY_API_RATE_LIMIT. The German and Russian translations are unreviewed.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the Player Counter query rate limit becomes configurable. The changeset adds a query_api_rate_limit setting, its environment variable, a settings field, translations…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the Player Counter query rate limit becomes configurable. The changeset adds a query_api_rate_limit setting, its environment variable, a settings field, translations, and a route provider change that reads the setting. The title is accurate and specific. The PR objectives name the environment key as PLAYER_COUNTER_QUERY_RATE_LIMIT, while the code summary uses PLAYER_COUNTER_QUERY_API_RATE_LIMIT. That naming mismatch does not affect the title check.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the minute rate,
Two requests pass through the gate.
Set zero, this limit rests,
The panel-wide rule still does its tests.
New labels help each setting show,
While server-keyed requests flow.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b660b9cb-221c-441e-8c7b-1dcc1ec5781a
Commits

Reviewing files that changed from the base of the PR and between ad8778e and 06d724d.

Files selected for processing: 6

  • player-counter/config/player-counter.php
  • player-counter/lang/de/query.php
  • player-counter/lang/en/query.php
  • player-counter/lang/ru/query.php
  • player-counter/src/PlayerCounterPlugin.php
  • player-counter/src/Providers/PlayerCounterRoutesProvider.php
Files skipped from review as they are similar to previous changes: 2

  • player-counter/lang/de/query.php
  • player-counter/lang/ru/query.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional comments: 2

player-counter/config/player-counter.php: 1

5-5: Data Integrity & Integration

The comment asks whether the PR description's key must remain supported. The later commit message records a rename to query_api_rate_limit, and the configuration reads the key it implies. The mismatch lies in the PR description, which is a superseded draft reference. No repository contract or existing public setting requires the old key. The question concerns maintainer intent, not a demonstrated defect in the changed code. The stated check cannot be turned into a code change from the supplied evidence.

player-counter/src/PlayerCounterPlugin.php: 1

62-62: Functional Correctness

The saved value takes effect on the next request in the normal save workflow. The cached-configuration scenario does not occur through this path.

@Boy132 Boy132 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename it to something like query_rate_api_limit to make it clear that the setting is for the api and not the query themselves.

@impaex

impaex commented Nov 15, 2026

Copy link
Copy Markdown
Author

@Boy132 as requested, I have changed the setting name.
I've renamed it to query_api_rate_limit (env: PLAYER_COUNTER_QUERY_API_RATE_LIMIT) and changed the label to "Query API rate limit". I went with this order so "rate limit" stays together, but I'm happy to switch to query_rate_api_limit if you prefer.

@impaex
impaex requested a review from Boy132 November 15, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants