Skip to content

merge dev to master#29

Merged
Aethersailor merged 6 commits intomasterfrom
dev
Feb 13, 2026
Merged

merge dev to master#29
Aethersailor merged 6 commits intomasterfrom
dev

Conversation

@Aethersailor
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 13, 2026 13:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request merges significant performance and infrastructure improvements from the dev branch to master, focusing on resource optimization for 1C1G (1 CPU, 1GB RAM) deployments.

Changes:

  • Introduced comprehensive caching layer with TTL-based bounded caches for DNS, GeoIP, GeoSite, and GitHub API calls
  • Added metrics collection and export system for monitoring performance and resource usage
  • Refactored event loop architecture to use single async event loop instead of mixing threads and asyncio
  • Implemented memory trimming helpers and conditional HTTP updates with ETag/Last-Modified support
  • Added profiling and stress testing tools for performance analysis

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tools/stress_sim.py New stress simulation tool for exercising core logic with concurrent workers
tools/profile_runtime.py New runtime profiler for collecting RSS, VMS, swap, CPU, and task metrics
tests/test_utils_cache_metrics.py Unit tests for TTLCache and MetricsStore
tests/test_data_manager.py Tests for DataManager scheduler lifecycle and session management
src/utils/metrics.py Lightweight metrics collection with counters, histograms, and periodic export
src/utils/memory.py Memory trimming helper using glibc malloc_trim
src/utils/cache.py Generic TTL-based bounded cache implementation
src/services/github_service.py Added file caching, metrics instrumentation, and io.StringIO usage
src/services/geoip_service.py Added location info caching with configurable size and TTL
src/services/dns_service.py Added A/NS record caching, semaphore concurrency control, and metrics
src/data_manager.py Refactored scheduler to asyncio, added conditional updates and GeoSite caching
src/config.py Added configuration options for caches, timeouts, metrics, and memory limits
src/main.py Unified event loop architecture, removed nested asyncio.run() calls
src/bot.py Improved lifecycle management, added metrics exporter startup
src/handlers/handler_manager.py Propagated cache configuration to services, added periodic cleanup
README.md Documented new environment variables and deployment recommendations
Comments suppressed due to low confidence (1)

src/handlers/handler_manager.py:228

  • The user_add_history dictionary is accessed and modified by multiple methods (check_user_add_limit, _maybe_cleanup_user_history, record_user_add) without any synchronization. While Python's GIL provides some protection, the cleanup operation in _maybe_cleanup_user_history iterates over items while potentially modifying the dict (pop), and check_user_add_limit also modifies the list for a specific user. If multiple Telegram handler callbacks run concurrently (which they can in python-telegram-bot), this could lead to race conditions. Consider adding a threading.Lock to protect these operations.
        self._maybe_cleanup_user_history()
        current_time = time.time()
        one_hour_ago = current_time - 3600  # 1小时前的时间戳
        
        # 清理1小时前的记录
        self.user_add_history[user_id] = [
            timestamp for timestamp in self.user_add_history[user_id]
            if timestamp > one_hour_ago
        ]
        
        # 检查当前小时内的添加次数
        current_count = len(self.user_add_history[user_id])
        remaining = self.MAX_ADDS_PER_HOUR - current_count
        
        return current_count < self.MAX_ADDS_PER_HOUR, remaining

    def _maybe_cleanup_user_history(self) -> None:
        now = time.time()
        if now - self._last_history_cleanup < 600:
            return
        cutoff = now - 3600
        for uid, timestamps in list(self.user_add_history.items()):
            filtered = [ts for ts in timestamps if ts > cutoff]
            if filtered:
                self.user_add_history[uid] = filtered
            else:
                self.user_add_history.pop(uid, None)
        self._last_history_cleanup = now
    
    def record_user_add(self, user_id: int):
        """记录用户添加操作"""
        current_time = time.time()
        self.user_add_history[user_id].append(current_time)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Aethersailor and others added 2 commits February 13, 2026 21:57
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Aethersailor Aethersailor merged commit 5815d7f into master Feb 13, 2026
4 checks passed
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.

1 participant