Skip to:
Content
Pages
Categories
Search
Top
Bottom

Simple meta_query painfully slow


  • yesbutmaybeno
    Participant

    @yesbutmaybeno

    I feel like I might just be out of luck but wondering if there’s some way to make this not so slow

    Refreshing the activity page and within 1 second there are 20 activites loaded in the stream.

    Adding this meta_query makes the wait time a solid 5 seconds.

    QUERY: Array
    (
        [type] => activity_update,created_group,new_avatar
        [action] => activity_update,created_group,new_avatar
        [populate_extras] => false
        [per_page] => 2
        [meta_query] => Array
            (
                [0] => Array
                    (
                        [key] => flagged_by_user_id
                        [compare] => NOT EXISTS
                    )
            )
    )

    It’s just checking if the activity has been “flagged”, and if there is a value it has been, so it should not be shown.

    (Even if I reduce per_page=2 it’s still the same amount of slow)

    Oddly, if I change it to “EXISTS” it’s very speedy. Only difference because only a few posts have that particular meta_key applied to them. I don’t understand why this is though because regardless if the key exists or not, the DB query check has to be performed. So why is it faster?

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    This due to mysql, not BP.
    EXISTS is always much faster.
    Look on the web, others have asked the same question in various context.


    yesbutmaybeno
    Participant

    @yesbutmaybeno

    Thank you. This is what I figured, but was wondering if there’s any strategy or extra parameters/changes that would speed it up? Aka using number comparison instead or something, since you mention the idea of one being faster than another.


    shanebp
    Moderator

    @shanebp

    No, it’s not a string vs integer issue.

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