Skip to content

Commit

Permalink
Fix: get cached responses from post type
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarssanchez committed Jun 21, 2022
1 parent 9d8b002 commit 8fdf270
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions includes/blocks/site-automation-block/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,19 @@ function render_block_callback( $attributes, $content, $block ) {
[
'post_name__in' => [ "sophi-site-automation-data-{$page_name}-{$widget_name}" ],
'post_type' => 'sophi-response',
'post_status' => 'draft',
'posts_per_page' => 1,
'fields' => 'ids',
'no_found_rows' => true,
'update_post_term_cache' => false
]
);

if ( $sophi_cached_response->found_posts ) {
if ( $sophi_cached_response->have_posts() ) {
$last_update = get_post_meta( $sophi_cached_response->posts[0], 'sophi_site_automation_last_updated', true );

if ( $last_update + 5 * MINUTE_IN_SECONDS > time() ) {
$curated_posts = get_post_meta( $sophi_cached_response->posts[0], 'sophi_site_automation_data' );
$curated_posts = get_post_meta( $sophi_cached_response->posts[0], 'sophi_site_automation_data', true );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion includes/classes/SiteAutomation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ public function get( $page, $widget, $timeout = 3 ) {
'post_type' => 'sophi-response',
'posts_per_page' => 1,
'fields' => 'ids',
'post_status' => 'draft',
'no_found_rows' => true,
'update_post_term_cache' => false
]
);

if ( $query->found_posts ) {
if ( $query->have_posts() ) {
$post_id = $query->posts[0];
$last_update = get_post_meta( $post_id, 'sophi_site_automation_last_updated', true );

Expand Down

0 comments on commit 8fdf270

Please sign in to comment.