Skip to content

Add an extra filter to fix the memory caching bug in Google Sheets #594

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 3 commits into from
Jun 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions inc/Integrations/Google/Sheets/GoogleSheetsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class GoogleSheetsIntegration {
public static function init(): void {
add_action( 'init', [ __CLASS__, 'register_blocks' ], 10, 0 );
add_filter( 'remote_data_blocks_request_details', [ __CLASS__, 'enhance_request_details' ], 10, 3 );
}

public static function register_blocks(): void {
Expand Down Expand Up @@ -186,4 +187,28 @@

return $snippets;
}

/**
* Due to the fact that we are using the same query for both the get and list queries, and
* only filtering out the results based on the input variables, the in-memory cache will not
* work as expected. This enhances the request details to include the input variables, so that
* the in-memory cache will be able to differenciate each request.
*
* @param array<string, mixed> $request_details The request details.
* @param string $query The query being executed.
* @param array<string, mixed> $input_variables The input variables for the current request.
* @return array<string, array{
* method: string,
* options: array<string, mixed>,
* origin: string,
* uri: string,
* }>
*/
public static function enhance_request_details( array $request_details, string $query, array $input_variables ): array {

Check failure on line 207 in inc/Integrations/Google/Sheets/GoogleSheetsIntegration.php

View workflow job for this annotation

GitHub Actions / Psalm

PossiblyUnusedParam

inc/Integrations/Google/Sheets/GoogleSheetsIntegration.php:207:81: PossiblyUnusedParam: Param #2 is never referenced in this method (see https://psalm.dev/134)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken this approach on purpose. I didn't want to alter the request_details method as it's technically working as expected in this case. The actual request doesn't really have any enhancements and we really shouldn't have data source specific logic in there.

Doing it this way means we let the integration handle it. Happy to have a discussion on this.

if ( isset( $request_details['origin'] ) && 'https://sheets.googleapis.com' === $request_details['origin'] && ! empty( $input_variables ) ) {
$request_details['input_variables'] = $input_variables;
}

return $request_details;
}
}
Loading