Skip to content
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

Fix %TOTALPAGES% caching #175

Merged
merged 10 commits into from
Feb 8, 2025
Merged

Fix %TOTALPAGES% caching #175

merged 10 commits into from
Feb 8, 2025

Conversation

Universal-Omega
Copy link
Owner

@Universal-Omega Universal-Omega commented Apr 29, 2022

Fixes #144 (comment)

Summary by CodeRabbit

  • Improvements
    • Enhanced internal handling of row count in data parsing and querying processes for better performance and reliability.

@Universal-Omega
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented May 17, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented May 17, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent changes streamline the handling of row counts in the parse function and the buildAndSelect method. The parse function now directly manages the rows array and its count element, while the buildAndSelect method no longer requires an external foundRows parameter, handling row count logic internally for improved clarity and efficiency.

Changes

File Path Change Summary
includes/Parse.php Modified parse function to handle rows['count'] internally and changed the check for foundRows.
includes/Query.php Updated buildAndSelect method to remove ?int &$foundRows parameter and adjusted internal logic.

🐰✨

In code's vast and winding maze,
We streamlined counts in clever ways.
No more external rows to find,
Internal logic, clear and kind.
With these changes, smooth and bright,
Our code now shines with sheer delight.

— CodeRabbit 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 376da33 and 6a77870.
Files selected for processing (2)
  • includes/Parse.php (3 hunks)
  • includes/Query.php (3 hunks)
Additional Context Used
Path-based Instructions (2)
includes/Parse.php (1)

Pattern **/*.php: Follow MediaWiki PHP Coding Standards:

Indentation:

  • Use tabs for indentation, not spaces.

Spaces:

  • Use spaces on either side of binary operators.
    Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect)
  • Add spaces inside parentheses, except where they are empty.
    Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect)
  • Do not add a space after a function name.
    Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)

Function Return Type Hint:

  • Add a space after the colon in the function return type hint.
    Example: function square( int $x ): int { return $x * $x; }

Arrays:

  • Use spaces in brackets when declaring an array, except where the array is empty.
    Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect)
  • Do not put spaces in brackets when accessing array elements.
    Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)

Control Structures:

  • Add a space after control structure keywords.
    Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)

Type Casting:

  • Do not use a space within or after the cast operator.
    Example: (int)$foo; (Correct) (int) $bar; (Incorrect)

Comments:

  • In comments, there should be one space between the # or // and the comment text.
    Example: // This is a comment. (Correct) //This is a comment. (Incorrect)

Ternary Operator:

  • Keep ternary operator expressions short and obvious.
  • For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.

File Formatting:
- Avoid trailing whitespace on lines.

includes/Query.php (1)

Pattern **/*.php: Follow MediaWiki PHP Coding Standards:

Indentation:

  • Use tabs for indentation, not spaces.

Spaces:

  • Use spaces on either side of binary operators.
    Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect)
  • Add spaces inside parentheses, except where they are empty.
    Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect)
  • Do not add a space after a function name.
    Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)

Function Return Type Hint:

  • Add a space after the colon in the function return type hint.
    Example: function square( int $x ): int { return $x * $x; }

Arrays:

  • Use spaces in brackets when declaring an array, except where the array is empty.
    Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect)
  • Do not put spaces in brackets when accessing array elements.
    Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)

Control Structures:

  • Add a space after control structure keywords.
    Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)

Type Casting:

  • Do not use a space within or after the cast operator.
    Example: (int)$foo; (Correct) (int) $bar; (Incorrect)

Comments:

  • In comments, there should be one space between the # or // and the comment text.
    Example: // This is a comment. (Correct) //This is a comment. (Incorrect)

Ternary Operator:

  • Keep ternary operator expressions short and obvious.
  • For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.

File Formatting:
- Avoid trailing whitespace on lines.

Additional comments not posted (6)
includes/Parse.php (2)

204-204: Ensure proper error handling for the buildAndSelect method call.

Verification successful

The buildAndSelect method in includes/Query.php includes proper error handling by checking the success of query modification functions and throwing an MWException if an error occurs.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `buildAndSelect` method properly handles errors and exceptions.

# Test: Search for the method implementation. Expect: Proper error handling mechanisms.
ast-grep --lang php --pattern $'class Query {
  $$$
  buildAndSelect($_, $_) {
    $$$
  }
  $$$  
}'

Length of output: 209



Script:

#!/bin/bash
# Description: Locate the `buildAndSelect` method implementation and verify its error handling.

# Search for the `buildAndSelect` method definition in the codebase.
rg 'function buildAndSelect' -t php

Length of output: 116



Script:

#!/bin/bash
# Description: Extract the implementation of the `buildAndSelect` method to verify its error handling.

# Extract the `buildAndSelect` method implementation from the `includes/Query.php` file.
rg -A 20 'function buildAndSelect' includes/Query.php

Length of output: 768


267-267: Consider verifying the existence of getRowCount method in Lister class.

Verification successful

The getRowCount method does exist in the Lister class.

  • Location: includes/Lister/Lister.php
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `getRowCount` method exists in the `Lister` class.

# Test: Search for the method implementation. Expect: Method definition in the `Lister` class.
ast-grep --lang php --pattern $'class Lister {
  $$$
  getRowCount() {
    $$$
  }
  $$$  
}'

Length of output: 201



Script:

#!/bin/bash
# Description: Verify that the `getRowCount` method exists in the `Lister` class.

# Search for the `Lister` class definition and then look for the `getRowCount` method within it.
rg -A 20 'class Lister' | rg 'function getRowCount'

Length of output: 53



Script:

#!/bin/bash
# Description: Verify the methods in the `Lister` class.

# Search for the `Lister` class definition and list all its methods.
rg -A 50 'class Lister' | rg 'function '

Length of output: 42



Script:

#!/bin/bash
# Description: Verify the existence of the `Lister` class.

# Search for the `Lister` class definition in the codebase.
rg 'class Lister'

Length of output: 61



Script:

#!/bin/bash
# Description: Verify the existence of the `getRowCount` method in the `Lister` class.

# Search for the `getRowCount` method in the `includes/Lister/Lister.php` file.
rg 'function getRowCount' includes/Lister/Lister.php

Length of output: 87

includes/Query.php (4)

171-171: Method signature change in buildAndSelect.

The removal of the ?int &$foundRows parameter simplifies the method signature and internalizes the row counting logic, aligning with the PR's objectives to manage caching more effectively.


378-378: Use of $dbr->selectField for FOUND_ROWS().

Switching to $dbr->selectField for retrieving the count of found rows is a more efficient approach than executing a separate query, which should help in reducing overhead and improving performance.


Line range hint 171-381: Complex SQL query construction logic.

The method effectively handles a variety of parameters to construct SQL queries dynamically. Exception handling for potential SQL build errors is appropriately managed, which is crucial for maintaining stability.


398-398: Caching mechanism implementation.

The implementation of caching using MediaWikiServices::getInstance()->getMainWANObjectCache() and handling with a pool counter is well-designed. This approach should improve performance by reducing database load and managing concurrent query executions effectively.

includes/Parse.php Outdated Show resolved Hide resolved
Copy link

@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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6a77870 and 68ba5fa.
Files selected for processing (2)
  • includes/Parse.php (3 hunks)
  • includes/Query.php (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • includes/Parse.php
  • includes/Query.php

* @param string $profilingContext Used to see the origin of a query in the profiling
* @return array|bool
*/
public function buildAndSelect( bool $calcRows = false, ?int &$foundRows = null, $profilingContext = '' ) {
public function buildAndSelect( bool $calcRows = false, $profilingContext = '' ) {

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports excessively long methods. Note

The method buildAndSelect() has 256 lines of code. Current threshold is set to 100. Avoid really long methods.
* @param string $profilingContext Used to see the origin of a query in the profiling
* @return array|bool
*/
public function buildAndSelect( bool $calcRows = false, ?int &$foundRows = null, $profilingContext = '' ) {
public function buildAndSelect( bool $calcRows = false, $profilingContext = '' ) {

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports methods with a large number of possible paths Note

The method buildAndSelect() has an NPath complexity of 1296000. The configured NPath complexity threshold is 200.
* @param string $profilingContext Used to see the origin of a query in the profiling
* @return array|bool
*/
public function buildAndSelect( bool $calcRows = false, ?int &$foundRows = null, $profilingContext = '' ) {
public function buildAndSelect( bool $calcRows = false, $profilingContext = '' ) {

Check notice

Code scanning / Phpmd (reported by Codacy)

This pattern reports methods with high cyclomatic complexity Note

The method buildAndSelect() has a Cyclomatic Complexity of 30. The configured cyclomatic complexity threshold is 10.
* @param string $profilingContext Used to see the origin of a query in the profiling
* @return array|bool
*/
public function buildAndSelect( bool $calcRows = false, ?int &$foundRows = null, $profilingContext = '' ) {
public function buildAndSelect( bool $calcRows = false, $profilingContext = '' ) {

Check warning

Code scanning / Phpmd (reported by Codacy)

You can fix this problem by extracting the logic in the boolean flag into its own class or method Warning

The method buildAndSelect has a boolean flag argument $calcRows, which is a certain sign of a Single Responsibility Principle violation.
static function ( $oldVal, &$ttl, &$setOpts ) use ( $worker, $db ){
$setOpts += Database::getCacheSetOptions( $db );
static function ( $oldVal, &$ttl, &$setOpts ) use ( $worker, $dbr ){
$setOpts += Database::getCacheSetOptions( $dbr );

Check warning

Code scanning / Phpmd (reported by Codacy)

Static access leads to hard to test code Warning

Avoid using static access to class '\Wikimedia\Rdbms\Database' in method 'buildAndSelect'.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
github-actions and others added 2 commits February 7, 2025 23:57
Check commit and GitHub actions for more details
@Universal-Omega Universal-Omega merged commit 280554f into master Feb 8, 2025
21 checks passed
@Universal-Omega Universal-Omega deleted the Universal-Omega-patch-5 branch February 8, 2025 00:05
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.

Use of %TOTALPAGES% in results header or footer causes both to disappear
1 participant