📢 Hivemind New Optimizations

in #steem11 hours ago

GitHub Pull Request Summary

https://github.com/steemit/hivemind/pull/360

Main Problem

The pull request aims to improve the performance and maintainability of the follow API and cache tools by optimizing SQL queries, introducing caching mechanisms, and enhancing cache inspection tools.

Proposed Changes

  • SQL Optimization:
    • Replace LEFT JOIN with INNER JOIN in get_followers and get_followers_by_page to improve performance by assuming data integrity (all follower IDs exist in hive_accounts).
    • Improve SQL query formatting and readability.
    • Add comments to explain the optimization rationale.
  • Code Optimization in bridge_api/methods.py:
    • Add result caching for get_post (TTL: 180s) and get_account_posts (TTL: 30s).
    • Extract _filter_hidden_posts helper function to eliminate code duplication.
    • Optimize hidden posts filtering logic using set operations to reduce time complexity from O(n²) to O(n).
    • Unify start parameter handling logic for better maintainability.
  • Cache Checker Tools Improvements:
    • Support reading Redis URL from the REDIS_URL environment variable in check_cache.py and check_cache_keys.py.
    • Update usage instructions to recommend using environment variables.
    • Add check_cache.py: Basic Redis cache validity check script.
    • Add check_cache_keys.py: Detailed cache key inspection script with statistics.
    • Add README.md: Comprehensive guide for cache troubleshooting and optimization.
Sort:  

Upvoted! Thank you for supporting witness @jswit.