Skip to content

Resolve long standing issue which prevents proper refresh of stats file data. #13348

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 1 commit into from
Apr 22, 2025

Conversation

rtibbles
Copy link
Member

@rtibbles rtibbles commented Apr 22, 2025

Summary

  • Fixes long running issue where stats file data would never get invalidated in developer mode.
  • I think this may have been hidden by hot reloading in the past, but I'm not quite sure why the issue here hasn't been more evident
  • This problem is most noticeable when developing on KDP

References

Fixes #9008

I suspect this to be the case ^ I never quite got a clear description of exactly what was happening, but things seem to work now

Reviewer guidance

Does development work as expected? If you do yarn run build, then pip install your kolibri repository into KDP development, are you able to use hot reload in the devserver?

Summary by CodeRabbit

  • Refactor
    • Improved internal caching behavior for certain operations, with more efficient handling outside of developer mode. No changes to visible features or user interface.

@github-actions github-actions bot added the DEV: backend Python, databases, networking, filesystem... label Apr 22, 2025
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

The change modifies the caching mechanism for the _stats_file_content property in the WebpackBundleHook class within kolibri/core/webpack/hooks.py. The decorator is switched from @cached_property to @property, and explicit caching logic is introduced to store the content in a private variable unless developer mode is enabled. The developer mode flag is now checked to determine whether to bypass or use the cache, ensuring that fresh content is loaded during development. No external APIs or method signatures are changed.

Changes

File(s) Change Summary
kolibri/core/webpack/hooks.py Replaced @cached_property with @property for _stats_file_content. Added explicit caching logic based on developer mode flag. Removed unused import.

Assessment against linked issues

Objective Addressed Explanation
Resolve hot reloading issues for external plugin development with kolibri-tools (#9008)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc1904 and d839fd7.

📒 Files selected for processing (1)
  • kolibri/core/webpack/hooks.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Python unit tests for currently supported Python versions (3.13)
  • GitHub Check: Python unit tests for EOL Python versions (3.8)
  • GitHub Check: Python unit tests for currently supported Python versions (3.12)
  • GitHub Check: Python unit tests for EOL Python versions (3.7)
  • GitHub Check: Python unit tests for currently supported Python versions (3.11)
  • GitHub Check: Python unit tests on Windows Server (3.8)
  • GitHub Check: Python unit tests for EOL Python versions (3.6)
  • GitHub Check: Python unit tests for currently supported Python versions (3.10)
  • GitHub Check: Python unit tests for currently supported Python versions (3.9)
  • GitHub Check: All file linting
  • GitHub Check: Python postgres unit tests
  • GitHub Check: Python unit tests on Mac OS (3.10)
  • GitHub Check: No zombies
  • GitHub Check: Build WHL file / Build WHL
🔇 Additional comments (4)
kolibri/core/webpack/hooks.py (4)

81-81: Appropriate decorator change for dynamic stat file refreshing.

Changing from @cached_property to @property allows the implementation of custom caching logic that can be bypassed in developer mode, which is essential for resolving the issue with stale stats file data.


87-90: Well-implemented conditional caching mechanism.

The implementation correctly:

  1. Stores the developer mode setting in a local variable for efficiency
  2. Returns cached content when available and not in developer mode
  3. Forces fresh data retrieval when in developer mode

This directly addresses the issue by ensuring stats file data is properly refreshed during development while maintaining caching benefits in production.


93-93: Good use of the local DEVELOPER_MODE variable for consistency.

Using the local variable instead of repeatedly accessing settings.DEVELOPER_MODE improves code consistency and prevents potential issues if the setting were to change during method execution.


112-113: Proper explicit caching implementation.

Explicitly storing the computed content in _cached_stats_file_content before returning completes the custom caching mechanism, replacing the implicit behavior of @cached_property with controlled caching that respects developer mode.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@LianaHarris360 LianaHarris360 self-requested a review April 22, 2025 18:22
Copy link
Member

@LianaHarris360 LianaHarris360 left a comment

Choose a reason for hiding this comment

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

Using hot reload and running the devserver in KDP now works as expected!

@rtibbles rtibbles merged commit 44cbc23 into learningequality:develop Apr 22, 2025
53 checks passed
@rtibbles rtibbles deleted the stats_cache branch April 22, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve hot reloading issues for external plugin development with kolibri-tools
2 participants