• Resolved David

    (@miladk)


    Hi,

    recently i saw that after updating a certain post, some other posts get purged too.

    After i checked the logs i found that it is purging 2 other posts alongside my original post which i have updated.

    The id 324654 is the id of the post i have updated.

    The two id’s 315548 and 46035 are the other two posts which will get purged alongside the original post too.

    How can i prevent this from happening so that the plugin only purges the post which i am editing and nothing else?

    10/15/24 22:00:10.306 [1.1.1.1:25990 1 ywl] ?? ——–purge_tags prev is: 46035
    10/15/24 22:00:10.306 [1.1.1.1.76:25990 1 ywl] ?? ——–purge_tags next is: 315548
    10/15/24 22:00:10.307 [1.1.1.1.76:25990 1 ywl] ?? added _Po.324654,_URL./xxx1-324654.html/,_W.recent-posts-1,_Po.46035,_Po.315548,_FD => LiteSpeed\Root::debug(?? added _Po.324654,_URL./xxx1-324654.html/,_W.recent-posts-1,_Po.46035,_Po.315548)@51 => LiteSpeed\Purge->_add(ARRAY)@501 => LiteSpeed\Purge::add(ARRAY)@473 => LiteSpeed\Purge->purge_post(324654)@885 => LiteSpeed\Purge->purge_publish(publish,publish)@89 => WP_Hook->apply_filters(ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
    /home/xxx/public_html/wp-includes/post.php@517 =>
    /home/xxx/public_html/wp-includes/post.php@5521
    10/15/24 22:00:10.307 [1.1.1.1:25990 1 ywl] ?? X-LiteSpeed-Purge: public,stale,f51_Po.324654,f51_URL./xxx1-324654.html/,f51_W.recent-posts-1,f51_Po.46035,f51_Po.315548,f51_FD
    10/15/24 22:00:10.307 [1.1.1.1:25990 1 ywl] ?? added _REST => LiteSpeed\Root::debug(?? added _REST,8)@51 => LiteSpeed\Purge->_add(ARRAY)@501 => LiteSpeed\Purge::add(REST)@473 => LiteSpeed\Purge->purge_post(324654)@887 => LiteSpeed\Purge->purge_publish(publish,publish)@89 => WP_Hook->apply_filters(ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
    /home/xxx/public_html/wp-includes/post.php@517 =>
    /home/xxx/public_html/wp-includes/post.php@5521
    10/15/24 22:00:10.307 [1.1.1.1:25990 1 ywl] ?? X-LiteSpeed-Purge: public,stale,f51_Po.324654,f51_URL./xxx1-324654.html/,f51_W.recent-posts-1,f51_Po.46035,f51_Po.315548,f51_FD,f51_REST

    • This topic was modified 1 month, 1 week ago by David.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support qtwrk

    (@qtwrk)

    please try

    if (class_exists('LiteSpeed\API')) { 
    remove_action('litespeed_purge_post', array(LiteSpeed\API::get_instance(), 'purge_post'));
    add_action('litespeed_purge_post', function($post_id) {
    @header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_Po." . $post_id);
    });
    }

    put it at your theme’s functions.php

    Thread Starter David

    (@miladk)

    The code didn’t work.

    It seems everytime a post gets updated the next and previous posts by date will get purged too which is strange.

    We are updating more than 30 posts per day, so that means about 60 additional posts gets purged too which is a problem for us.

    Plugin Support qtwrk

    (@qtwrk)

    emmm , okay , it’s not easy to modify plugin’s function without modify the source , I will see if I can come up something.

    Plugin Support qtwrk

    (@qtwrk)

    I have worked code to suppress edit exsiting post to only purge itself

    what about the new publish post ? if you only purge post id itself, elsewhere like home , category won’t show the new post

    Thread Starter David

    (@miladk)

    I definitely need to ensure that the front page and category pages are purged as well. However, I would like to avoid purging any other posts while I’m in the process of editing or creating a new post.

    Plugin Support qtwrk

    (@qtwrk)

    add_action('wp_loaded', function() {
    $request_uri = $_SERVER['REQUEST_URI'];

    function add_back_purge_header($post_id = null) {
    ob_start(function($buffer) use ($post_id) {
    if ($post_id) {
    $categories = get_the_category($post_id);
    $category_list = [];

    if (!empty($categories)) {
    foreach ($categories as $category) {
    $category_list[] = LSWCP_TAG_PREFIX . "_T." . $category->term_id;
    }
    }

    $category_tag = implode(',', $category_list);
    @header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_H," . LSWCP_TAG_PREFIX . "_FD," . LSWCP_TAG_PREFIX . "_Po." . $post_id . ( $category_tag ? ", " . $category_tag : ''));
    } else {
    @header('X-LiteSpeed-Purge: nothing');
    }
    return $buffer;
    });
    }


    # if (isset($_POST['_wp_http_referer']) && $_POST['_wp_http_referer'] !== '/wp-admin/post-new.php') {
    # put back this if to allow normal purge on publish new post action
    $parsed_url = parse_url($request_uri);

    if (isset($parsed_url['path']) && strpos($parsed_url['path'], '/wp-admin/post.php') !== false) {
    if (isset($parsed_url['query'])) {
    parse_str($parsed_url['query'], $query_params);
    if (isset($query_params['post'], $query_params['action']) && $query_params['action'] === 'edit') {
    $post_id = intval($query_params['post']);
    add_back_purge_header($post_id);
    }
    }
    }
    # }
    if (strpos($request_uri, "/wp-json/wp/v2/posts") !== false) {
    add_back_purge_header();
    }
    });


    okay , try this , it should suppress normal purge action , and when publish/edit a post , purge post itself , assigned categories and homepage.

    Thread Starter David

    (@miladk)

    I added the code to the top of my functions.php, but unfortunately, it still doesn’t work.

    After updating a post, the previous and next post changes from x-litespeed-cache: hit to x-litespeed-cache: miss on the same browser session when refreshing it.

    • This reply was modified 1 month ago by David.
    Plugin Support qtwrk

    (@qtwrk)

    is that post post ? or other post type ?

    I tested my code on wp with theme 2021 on normal post it works

    Thread Starter David

    (@miladk)

    The other posts of course, same post type but different posts (i’m testing the example i provided in the beginning of this). everytime post 324654? get’s updated, post 46035 and 315548 will get purged too.

    If it is working for you then there is maybe something wrong in my template, i will try to find the issue and check the logs again

    • This reply was modified 1 month ago by David.
    Thread Starter David

    (@miladk)

    I have tested it again, and it seems to work now.

    Thank you

    Plugin Support qtwrk

    (@qtwrk)

    meanwhile , please try my code on the default wp + default theme (like 2021 or something) , and check if it works as you expected

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.