Repository navigation
fix(admin): address Greptile moderation follow-ups from #941 #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bc73fa7
fix(admin): address Greptile moderation follow-ups from #941
Ferryx349 3696f3e
chore(changeset): admin moderation Greptile follow-ups (#941)
Ferryx349 527b1af
fix(admin): address Greptile review on moderation follow-ups
Ferryx349 a6804dd
Merge branch 'main' into fix/admin-moderation-greptile
Ferryx349 f1c52bd
fix(admin): harden settings lock and moderation stats
Ferryx349 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "nostream": patch | ||
| --- | ||
|
|
||
| fix(admin): Greptile follow-ups for moderation limits and activity stats | ||
|
|
||
| Moderation limit PATCH and ban/unban actions could interleave read–update–save across workers and drop updates. Those paths now run under an async settings write lock that yields while waiting and reclaims stale locks without deleting a fresh holder’s file. Activity stats windows filter on `first_seen` (when the relay first saw the event), not `event_created_at`, with partial indexes on live rows for those queries. IPv6 addresses on the rate-limit bypass list are normalized the same way as connection IPs so bypass rules cannot be skipped by formatting, including when removing entries stored in another spelling. PATCH rejects kind ranges with `start` greater than `end`. PATCH and moderation actions return the normalized limits read back from settings after save. |
59 changes: 59 additions & 0 deletions
59
migrations/20261025_120000_add_moderation_stats_first_seen_indexes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Supports admin moderation activity stats (queryTopPublishingPubkeys / | ||
| * queryTopClientIps), which filter live events by relay receipt time: | ||
| * | ||
| * WHERE deleted_at IS NULL AND first_seen >= ? | ||
| * | ||
| * Partial indexes keep the working set small on relays where most rows are | ||
| * soft-deleted history. CREATE INDEX CONCURRENTLY cannot run inside a | ||
| * transaction. | ||
| */ | ||
|
|
||
| exports.config = { transaction: false } | ||
|
|
||
| const INDEX_NAMES = [ | ||
| 'events_live_first_seen_pubkey_idx', | ||
| 'events_live_first_seen_remote_address_idx', | ||
| ] | ||
|
|
||
| // A failed concurrent build leaves the index behind as invalid. `IF NOT EXISTS` | ||
| // would then skip it on retry, leaving the migration successful but the index | ||
| // unusable. Drop any invalid leftover before recreating it. | ||
| const dropInvalidIndex = async (knex, indexName) => { | ||
| const result = await knex.raw( | ||
| ` | ||
| SELECT 1 | ||
| FROM pg_index | ||
| WHERE indexrelid = to_regclass(?) | ||
| AND NOT indisvalid | ||
| `, | ||
| [indexName], | ||
| ) | ||
|
|
||
| if (result.rows.length > 0) { | ||
| await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS ??', [indexName]) | ||
| } | ||
| } | ||
|
|
||
| exports.up = async function (knex) { | ||
| for (const indexName of INDEX_NAMES) { | ||
| await dropInvalidIndex(knex, indexName) | ||
| } | ||
|
|
||
| await knex.raw(` | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS events_live_first_seen_pubkey_idx | ||
| ON events (first_seen, event_pubkey) | ||
| WHERE deleted_at IS NULL | ||
| `) | ||
|
|
||
| await knex.raw(` | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS events_live_first_seen_remote_address_idx | ||
| ON events (first_seen, remote_address) | ||
| WHERE deleted_at IS NULL AND remote_address IS NOT NULL | ||
| `) | ||
| } | ||
|
|
||
| exports.down = async function (knex) { | ||
| await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS events_live_first_seen_remote_address_idx') | ||
| await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS events_live_first_seen_pubkey_idx') | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.