Skip to content

Prevent divide-by-zero errors in cache_score function #7026

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jc-harrison
Copy link
Member

@jc-harrison jc-harrison commented May 12, 2025

Closes #7027

I have:

  • Formatted any Python files with black
  • Brought the branch up to date with master
  • Added any relevant Github labels
  • Added tests for any new additions
  • Added or updated any relevant documentation
  • Added an Architectural Decision Record (ADR), if appropriate
  • Added an MPLv2 License Header if appropriate
  • Updated the Changelog

Description

We already had a safeguard in the FlowDB touch_cache function to increase table size to a non-zero value. This PR moves the safeguard into cache_score, so that it takes effect everywhere cache_score is used.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cache score calculation to prevent errors with very small or zero table sizes, ensuring more reliable performance when handling cache operations.

Copy link
Contributor

coderabbitai bot commented May 12, 2025

Walkthrough

The update revises the handling of the tablesize parameter in SQL utility functions. The cache_score function now internally applies a lower bound to tablesize using the greatest function, and touch_cache is updated to pass raw values rather than pre-processed ones. Function signatures and internal logic were adjusted accordingly.

Changes

File(s) Change Summary
flowdb/bin/build/0030_utilities.sql Updated cache_score to apply greatest to tablesize internally; modified touch_cache to pass unprocessed tablesize directly to cache_score.

Assessment against linked issues

Objective Addressed Explanation
Ensure tablesize used in cache_score is always > 0 to prevent divide-by-zero errors (#7027)

Poem

A hop, a skip, a database tweak,
Cache scores now stronger, never weak!
No more fears of zero divide,
With greatest guards now set inside.
Rabbits cheer with every run—
Safe and sound, the queries fun!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 3bc5e3c and f175866.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CodeQL-Build
  • GitHub Check: Summary
  • GitHub Check: run_build_pipeline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
flowdb/bin/build/0030_utilities.sql (1)

270-270: Internalise divide-by-zero guard in cache_score
Centralising the greatest(tablesize, 0.00001) check inside cache_score is an improvement for robustness. As an enhancement, consider declaring the function IMMUTABLE (since it has no side effects and depends only on its inputs) and adding the STRICT modifier to explicitly handle NULL inputs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f664158 and a517f87.

📒 Files selected for processing (1)
  • flowdb/bin/build/0030_utilities.sql (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CodeQL-Build
  • GitHub Check: Summary
  • GitHub Check: run_build_pipeline

@jc-harrison jc-harrison added bug Something isn't working FlowDB Issues related to FlowDB labels May 12, 2025
Copy link

cypress bot commented May 12, 2025

FlowAuth    Run #24628

Run Properties:  status check failed Failed #24628  •  git commit f17586679b: Merge branch 'fix-cache-score' of github.com:Flowminder/FlowKit into fix-cache-s...
Project FlowAuth
Branch Review fix-cache-score
Run status status check failed Failed #24628
Run duration 03m 13s
Commit git commit f17586679b: Merge branch 'fix-cache-score' of github.com:Flowminder/FlowKit into fix-cache-s...
Committer James Harrison
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 6
Tests that passed  Passing 36
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/role_list.js • 1 failed test

View Output

Test Artifacts
role list screen > Add blank role Test Replay Screenshots
Flakiness  add_new_server.js • 2 flaky tests

View Output

Test Artifacts
Server management > Add duplicate Server name Test Replay Screenshots
Server management > Add server Test Replay Screenshots
Flakiness  add_new_user.js • 1 flaky test

View Output

Test Artifacts
User management > Add password with less strength Test Replay Screenshots

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Member

@greenape greenape left a comment

Choose a reason for hiding this comment

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

LGTM. Worth adding a test case for the bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FlowDB Issues related to FlowDB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Divide-by-zero error in cache_score
2 participants