Skip to content

Fix false values coming from cache at cache level#2416

Merged
Crabcyborg merged 1 commit into
masterfrom
fix_false_values_coming_from_cache_at_cache_level
Jul 9, 2025
Merged

Fix false values coming from cache at cache level#2416
Crabcyborg merged 1 commit into
masterfrom
fix_false_values_coming_from_cache_at_cache_level

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jul 9, 2025

Related ticket https://secure.helpscout.net/conversation/2996345861/234022

The previous fix didn't really catch everything. Other code calls check_cache directly.

Pre-release
formidable-6.22.3b.zip

@Crabcyborg Crabcyborg added this to the 6.22.2 milestone Jul 9, 2025
@Crabcyborg Crabcyborg marked this pull request as ready for review July 9, 2025 20:17
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 9, 2025

Walkthrough

This update modifies the FrmDb class by simplifying the implementations of the get_col and get_results methods to remove redundant array checks. It also updates the check_cache method to ensure that, for 'get_col' and 'get_results' query types, non-array cached results are normalized to empty arrays before returning.

Changes

File(s) Change Summary
classes/models/FrmDb.php Simplified get_col and get_results to remove redundant array checks; updated check_cache to return empty arrays for non-array cached results in specific query types.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant FrmDb

    Caller->>FrmDb: get_col(...) / get_results(...)
    FrmDb->>FrmDb: check_cache(...)
    alt Cache hit
        FrmDb->>FrmDb: If type is get_col/get_results and cached result is not array
        FrmDb-->>Caller: Return []
    else Cache miss or valid array
        FrmDb-->>Caller: Return cached result
    end
Loading

Possibly related PRs

  • Strategy11/formidable-forms#2413: Both PRs modify the get_col and get_results methods in FrmDb.php to ensure these functions consistently return arrays, with the main PR additionally refining cache handling for these query types.
  • Strategy11/formidable-forms#2401: Both PRs modify the check_cache method in FrmDb.php to improve cache handling, with the main PR adding type-specific return normalization and the retrieved PR changing cache existence detection using the "found" parameter in wp_cache_get.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.15)

Note: Using configuration file /phpstan.neon.
Invalid configuration:
Unexpected item 'parameters › strictRules'.


📜 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 61a5802 and d1eefb2.

📒 Files selected for processing (1)
  • classes/models/FrmDb.php (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Cypress
  • GitHub Check: Cypress
🔇 Additional comments (3)
classes/models/FrmDb.php (3)

259-259: Good refactoring to centralize array normalization.

The simplification of get_col to delegate directly to get_var with type 'col' is a good improvement that removes redundant array checking logic. This change aligns with the centralized approach implemented in the check_cache method.


290-290: Consistent with the centralized approach.

The simplification of get_results mirrors the get_col change and correctly delegates to get_var with type 'results'. This maintains consistency with the centralized array normalization strategy.


661-663: Effective centralized solution for false cache values.

The addition of this conditional check properly addresses the core issue by ensuring that non-array cached results are normalized to empty arrays for both 'get_col' and 'get_results' query types. This handles the case where check_cache is called directly, which was the gap in the previous fix.

The type matching logic correctly corresponds to the types passed from get_var method (which appends 'get_' prefix to 'col' and 'results').

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@Crabcyborg Crabcyborg merged commit 088fe7d into master Jul 9, 2025
34 checks passed
@Crabcyborg Crabcyborg deleted the fix_false_values_coming_from_cache_at_cache_level branch July 9, 2025 20:22
@Crabcyborg Crabcyborg modified the milestones: 6.22.2, 6.22.3 Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant