Skip to content

Commit fabc737

Browse files
author
Marco Pereirinha
committed
Do a late flush the cache
1 parent 725fe54 commit fabc737

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

php/class-delivery.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ public function unsync_size_relationship( $attachment_id ) {
484484
self::update_size_relations_public_id( $attachment_id, null );
485485
self::update_size_relations_state( $attachment_id, 'disable' );
486486
self::update_size_relations_transformations( $attachment_id, null );
487-
488-
do_action( 'cloudinary_flush_cache' );
489487
}
490488

491489
/**
@@ -555,7 +553,6 @@ public static function update_size_relations_state( $attachment_id, $state ) {
555553
*/
556554
public static function update_size_relations_transformations( $attachment_id, $transformations ) {
557555
Relate::update_transformations( $attachment_id, $transformations );
558-
do_action( 'cloudinary_flush_cache' );
559556
}
560557

561558
/**

php/relate/class-relationship.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function save() {
105105
if ( ! $this->save_on_shutdown ) {
106106
$this->save_on_shutdown = true;
107107
add_action( 'shutdown', array( $this, 'do_save' ) );
108+
add_action( 'shutdown', array( $this, 'flush_cache' ), 100 );
108109
}
109110
}
110111

@@ -115,9 +116,23 @@ public function save() {
115116
*/
116117
public function do_save() {
117118
global $wpdb;
118-
$data = $this->get_data();
119+
$data = $this->get_data();
120+
$update = false;
119121

120-
return $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
122+
if ( ! empty( $data['id'] ) ) {
123+
$update = $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
124+
}
125+
126+
return $update;
127+
}
128+
129+
/**
130+
* Flush the cache.
131+
*
132+
* @return void
133+
*/
134+
public function flush_cache() {
135+
do_action( 'cloudinary_flush_cache', false );
121136
}
122137

123138
/**

0 commit comments

Comments
 (0)