Skip to content

Commit b5a7f89

Browse files
authored
Add an extra filter to fix the memory caching bug in Google Sheets (#594)
* Add an extra filter to fix the memory caching bug * Fix the psalm erro * Fix psalm again
1 parent a2cb895 commit b5a7f89

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

inc/Integrations/Google/Sheets/GoogleSheetsIntegration.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class GoogleSheetsIntegration {
1212
public static function init(): void {
1313
add_action( 'init', [ __CLASS__, 'register_blocks' ], 10, 0 );
14+
add_filter( 'remote_data_blocks_request_details', [ __CLASS__, 'enhance_request_details' ], 10, 3 );
1415
}
1516

1617
public static function register_blocks(): void {
@@ -186,4 +187,28 @@ public static function get_block_registration_snippets( array $data_source_confi
186187

187188
return $snippets;
188189
}
190+
191+
/**
192+
* Due to the fact that we are using the same query for both the get and list queries, and
193+
* only filtering out the results based on the input variables, the in-memory cache will not
194+
* work as expected. This enhances the request details to include the input variables, so that
195+
* the in-memory cache will be able to differenciate each request.
196+
*
197+
* @param array<string, mixed> $request_details The request details.
198+
* @param string $_query The query being executed.
199+
* @param array<string, mixed> $input_variables The input variables for the current request.
200+
* @return array<string, array{
201+
* method: string,
202+
* options: array<string, mixed>,
203+
* origin: string,
204+
* uri: string,
205+
* }>
206+
*/
207+
public static function enhance_request_details( array $request_details, string $_query, array $input_variables ): array {
208+
if ( isset( $request_details['origin'] ) && 'https://sheets.googleapis.com' === $request_details['origin'] && ! empty( $input_variables ) ) {
209+
$request_details['input_variables'] = $input_variables;
210+
}
211+
212+
return $request_details;
213+
}
189214
}

0 commit comments

Comments
 (0)