@@ -737,6 +737,147 @@ public function test_meta_query_compare_not_exists_with_another_condition_relati
737737 $ this ->assertSameSets ( $ expected , $ query ->posts );
738738 }
739739
740+ /**
741+ * @ticket 64696
742+ */
743+ public function test_jit_meta_query_invalidation_adding_meta () {
744+ $ post_id = self ::factory ()->post ->create ();
745+ wp_cache_set_posts_last_changed ();
746+ $ posts_last_changed_initial = wp_cache_get_last_changed ( 'posts ' );
747+
748+ // Query posts by meta data.
749+ $ query = new WP_Query (
750+ array (
751+ 'fields ' => 'ids ' ,
752+ 'meta_query ' => array (
753+ array (
754+ 'key ' => 'foo ' ,
755+ 'value ' => 'bar ' ,
756+ ),
757+ ),
758+ )
759+ );
760+ $ this ->assertNotContains ( $ post_id , $ query ->posts , 'Post should not be in results without meta data. ' );
761+
762+ // Add post meta.
763+ add_post_meta ( $ post_id , 'foo ' , 'bar ' );
764+
765+ // Confirm last changed has not updated.
766+ $ this ->assertSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'Adding meta data should not invalidate post query cache. ' );
767+
768+ // Query posts by meta data.
769+ $ query = new WP_Query (
770+ array (
771+ 'fields ' => 'ids ' ,
772+ 'meta_query ' => array (
773+ array (
774+ 'key ' => 'foo ' ,
775+ 'value ' => 'bar ' ,
776+ ),
777+ ),
778+ )
779+ );
780+
781+ // Confirm JIT last changed has updated.
782+ $ this ->assertNotSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'JIT meta query should invalidate post query cache. ' );
783+ $ this ->assertContains ( $ post_id , $ query ->posts , 'Queried post should be in results. ' );
784+ }
785+
786+ /**
787+ * @ticket 64696
788+ */
789+ public function test_jit_meta_query_invalidation_updating_meta () {
790+ $ post_id = self ::factory ()->post ->create ();
791+ wp_cache_set_posts_last_changed ();
792+ add_post_meta ( $ post_id , 'foo ' , 'bar ' );
793+
794+ // Query posts by meta data.
795+ $ query = new WP_Query (
796+ array (
797+ 'fields ' => 'ids ' ,
798+ 'meta_query ' => array (
799+ array (
800+ 'key ' => 'foo ' ,
801+ 'value ' => 'baz ' ,
802+ ),
803+ ),
804+ )
805+ );
806+ $ this ->assertNotContains ( $ post_id , $ query ->posts , 'Post should not be in results with meta data before update. ' );
807+ $ posts_last_changed_initial = wp_cache_get_last_changed ( 'posts ' );
808+
809+ // Update post meta.
810+ update_post_meta ( $ post_id , 'foo ' , 'baz ' );
811+
812+ // Confirm last changed has not updated.
813+ $ this ->assertSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'Updating meta data should not invalidate post query cache. ' );
814+
815+ // Query posts by meta data.
816+ $ query = new WP_Query (
817+ array (
818+ 'fields ' => 'ids ' ,
819+ 'meta_query ' => array (
820+ array (
821+ 'key ' => 'foo ' ,
822+ 'value ' => 'baz ' ,
823+ ),
824+ ),
825+ )
826+ );
827+
828+ // Confirm JIT last changed has updated.
829+ $ this ->assertNotSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'JIT meta query should invalidate post query cache. ' );
830+ $ this ->assertContains ( $ post_id , $ query ->posts , 'Queried post should be in results. ' );
831+ }
832+
833+
834+ /**
835+ * @ticket 64696
836+ */
837+ public function test_jit_meta_query_invalidation_deleting_meta () {
838+ $ post_id = self ::factory ()->post ->create ();
839+ wp_cache_set_posts_last_changed ();
840+ add_post_meta ( $ post_id , 'foo ' , 'bar ' );
841+
842+ // Query posts by meta data.
843+ $ query = new WP_Query (
844+ array (
845+ 'fields ' => 'ids ' ,
846+ 'meta_query ' => array (
847+ array (
848+ 'key ' => 'foo ' ,
849+ 'value ' => 'bar ' ,
850+ ),
851+ ),
852+ )
853+ );
854+ $ this ->assertContains ( $ post_id , $ query ->posts , 'Post should be in results with meta data before meta data deleted. ' );
855+ $ posts_last_changed_initial = wp_cache_get_last_changed ( 'posts ' );
856+
857+ // Delete post meta.
858+ delete_post_meta ( $ post_id , 'foo ' );
859+
860+ // Confirm last changed has not updated.
861+ $ this ->assertSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'Deleting meta data should not invalidate post query cache. ' );
862+
863+ // Query posts by meta data.
864+ $ query = new WP_Query (
865+ array (
866+ 'fields ' => 'ids ' ,
867+ 'meta_query ' => array (
868+ array (
869+ 'key ' => 'foo ' ,
870+ 'value ' => 'bar ' ,
871+ ),
872+ ),
873+ )
874+ );
875+
876+ // Confirm JIT last changed has updated.
877+ $ this ->assertNotSame ( $ posts_last_changed_initial , wp_cache_get_last_changed ( 'posts ' ), 'JIT meta query should invalidate post query cache. ' );
878+ $ this ->assertNotContains ( $ post_id , $ query ->posts , 'Queried post should not be in results after meta data deleted. ' );
879+ }
880+
740881 /**
741882 * @ticket 24093
742883 */
0 commit comments