Repository navigation
chore: Improve gifts indexing - #255
Merged
Merged
Conversation
…API exceptions This adds an asyncio.sleep(0.250) on close to allow aiohttp SSL transports to cleanly disconnect, preventing SIGKILL from file descriptor leaks. It also ensures 'user not found' exceptions are correctly raised rather than wiping a user's DB gifts.
danoctua
force-pushed
the
chore/improve-gifts-indexing
branch
2 times, most recently
from
September 25, 2026 13:45
e626f79 to
536526c
Compare
…sers - Moves batch syncing into IndexerUserGiftAction to share a single BotApiGiftIndexer instance, vastly reducing overhead and event loop thrashing. - Adds UserService.mark_as_blocked() and excludes blocked users from global fetches. - Automatically marks users as blocked when Telegram returns a 'user not found' exception during gift sync.
danoctua
force-pushed
the
chore/improve-gifts-indexing
branch
from
September 25, 2026 13:49
536526c to
aabd84b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Optimize Gift Indexer Resource Allocation and Auto-Block Deleted Accounts
Description
This pull request addresses two significant stability issues within the Telegram unique gifts indexer related to background Celery workers. First, it resolves resource exhaustion (
SIGKILL) caused by file descriptor leaks and event loop thrashing when polling batches of users. Second, it gracefully handles "Bad Request: user not found" exceptions byautomatically marking deleted Telegram accounts as inactive, ensuring they are excluded from future syncs.
Fixes: # (add issue number if applicable)
Checklist
Before submitting your pull request, please ensure the following:
Changes
refresh_users_gifts_batchto execute all 25 users within a singleasyncio.run()loop insideIndexerUserGiftAction, sharing a singleBotApiGiftIndexerinstance. This heavily cuts down event loop setup/teardown churn and drops SSL connection creation by 96%.
asyncio.sleep(0.250)duringindexer.close()to giveaiohttpthe necessary event loop tick to elegantly terminate underlying SSL connections, preventingOS-level file descriptor leaks leading to
SIGKILL.TelegramBadRequestexceptions correctly raise instead of silently continuing, preventing the indexer from falsely assuming users have lost all their gifts.is_blocked = Truevia a newUserService. mark_as_blockedmethod.UserService.get_all_telegram_idsto exclude blocked users entirely, preventing the global dispatcher from unnecessarily re-queueing deleted accounts.How Has This Been Tested?
pre-commit(Ruff/ESLint).Screenshots (if applicable)
N/A
Additional Notes
The
sync_user_giftsmethod was updated to accept an optionalindexerparameter to allow the single-user priority task (Flow B) to remain unchanged while still benefiting from theperformance optimizations in the master dispatcher (Flow C).
Thank you for contributing! 🎉