Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination with query callback broke pagination in last meilisearch version #535

Closed
eliasjtg opened this issue Oct 1, 2021 · 8 comments
Closed

Comments

@eliasjtg
Copy link

eliasjtg commented Oct 1, 2021

  • Scout Version: 9.2.9
  • Scout Driver: MeiliSearch 0.22
  • Laravel Version:8.61.0
  • PHP Version: 8.0.9
  • Database Driver & Version: mysql 8.0.26-0ubuntu0.20.04.2

Description:

After upgrade meilisearch to 0.22 and upgrade meilisearch-php 0.19.1 the pagination is broken when queryCallback is provided.

image
Builder.php:398 return $totalCount that is always 0

When ->query() callback don't passed, pagination work perfectly

return Post::search($search)->paginate(5);

image

Steps To Reproduce:

Using query() reproduce the bug

return Post::search($search)->query(function($query) {
    $query->with('image');
})->paginate(5);

image

@driesvints
Copy link
Member

Did you restart Meilisearch after upgrading?

@eliasjtg
Copy link
Author

eliasjtg commented Oct 4, 2021

I'm using Homestead, i do vagrant reload --provision

This happening in my team and in production vps

@mmachatschek
Copy link
Contributor

@eliasjtg can you post the result of return Post::search($search)->paginateRaw(5); so we can verify if this is an issue with scout or with meilisearch?

@eliasjtg
Copy link
Author

eliasjtg commented Oct 4, 2021

A workaround was remove all ->query() callbacks and do the query in the model overriding queryScoutModelsByIds() function

@eliasjtg
Copy link
Author

eliasjtg commented Oct 4, 2021

@eliasjtg can you post the result of return Post::search($search)->paginateRaw(5); so we can verify if this is an issue with scout or with meilisearch?

Working on it

@eliasjtg
Copy link
Author

eliasjtg commented Oct 4, 2021

@mmachatschek

The output:

{
  "current_page": 1,
  "data": {
    "hits": [
      {
        "title": "My first post",
        "description": "It's my first post",
        "id": "1633101447865131000",
        "amount": "1",
        "city_id": 1633100293859345000,
        "category_id": 1633101141456362000,
        "sale": 1,
        "created_at": 1633101447,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My second post",
        "description": "My second post",
        "id": "1633101566197075000",
        "amount": "2",
        "city_id": 1633100293859345000,
        "category_id": 1633101141456362000,
        "sale": 1,
        "created_at": 1633101566,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My third post",
        "description": "My third post",
        "id": "1633101690961604000",
        "amount": "3",
        "city_id": 1633100293859345000,
        "category_id": 1633099535387689000,
        "sale": 1,
        "created_at": 1633101690,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633099495361081000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My fourth post",
        "description": "My fourth post",
        "id": "1633101737580754000",
        "amount": "4",
        "city_id": 1633100293859345000,
        "category_id": 1633099535387689000,
        "sale": 1,
        "created_at": 1633101737,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633099495361081000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My fifth post",
        "description": "My fifth post",
        "id": "1633101911172782000",
        "amount": "5",
        "city_id": 1633100293859345000,
        "category_id": 1633101767626905000,
        "sale": 1,
        "created_at": 1633101911,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      }
    ],
    "nbHits": 8,
    "exhaustiveNbHits": false,
    "query": "",
    "limit": 5,
    "offset": 0,
    "processingTimeMs": 0
  },
  "first_page_url": "https://api.myklick.local/app/post/home?query=&page=1",
  "from": 1,
  "last_page": 2,
  "last_page_url": "https://api.myklick.local/app/post/home?query=&page=2",
  "links": [
    {
      "url": null,
      "label": "Anterior",
      "active": false
    },
    {
      "url": "https://api.myklick.local/app/post/home?query=&page=1",
      "label": "1",
      "active": true
    },
    {
      "url": "https://api.myklick.local/app/post/home?query=&page=2",
      "label": "2",
      "active": false
    },
    {
      "url": "https://api.myklick.local/app/post/home?query=&page=2",
      "label": "Próximo",
      "active": false
    }
  ],
  "next_page_url": "https://api.myklick.local/app/post/home?query=&page=2",
  "path": "https://api.myklick.local/app/post/home",
  "per_page": 5,
  "prev_page_url": null,
  "to": 7,
  "total": 8
}

@eliasjtg
Copy link
Author

eliasjtg commented Oct 4, 2021

if i do Post::search($search)->query(function($query) {})->paginateRaw(5);

{
  "current_page": 1,
  "data": {
    "hits": [
      {
        "title": "My first post",
        "description": "It's my first post",
        "id": "1633101447865131000",
        "amount": "1",
        "city_id": 1633100293859345000,
        "category_id": 1633101141456362000,
        "sale": 1,
        "created_at": 1633101447,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My second post",
        "description": "My second post",
        "id": "1633101566197075000",
        "amount": "2",
        "city_id": 1633100293859345000,
        "category_id": 1633101141456362000,
        "sale": 1,
        "created_at": 1633101566,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My third post",
        "description": "My third post",
        "id": "1633101690961604000",
        "amount": "3",
        "city_id": 1633100293859345000,
        "category_id": 1633099535387689000,
        "sale": 1,
        "created_at": 1633101690,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633099495361081000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My fourth post",
        "description": "My fourth post",
        "id": "1633101737580754000",
        "amount": "4",
        "city_id": 1633100293859345000,
        "category_id": 1633099535387689000,
        "sale": 1,
        "created_at": 1633101737,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633099495361081000
        ],
        "parent_category_fathers": null
      },
      {
        "title": "My fifth post",
        "description": "My fifth post",
        "id": "1633101911172782000",
        "amount": "5",
        "city_id": 1633100293859345000,
        "category_id": 1633101767626905000,
        "sale": 1,
        "created_at": 1633101911,
        "user_deleted": 0,
        "parent_category": null,
        "category_fathers": [
          1633101121627163000
        ],
        "parent_category_fathers": null
      }
    ],
    "nbHits": 8,
    "exhaustiveNbHits": false,
    "query": "",
    "limit": 5,
    "offset": 0,
    "processingTimeMs": 0
  },
  "first_page_url": "https://api.myklick.local/app/post/home?query=&page=1",
  "from": 1,
  "last_page": 1,
  "last_page_url": "https://api.myklick.local/app/post/home?query=&page=1",
  "links": [
    {
      "url": null,
      "label": "Anterior",
      "active": false
    },
    {
      "url": "https://api.myklick.local/app/post/home?query=&page=1",
      "label": "1",
      "active": true
    },
    {
      "url": null,
      "label": "Próximo",
      "active": false
    }
  ],
  "next_page_url": null,
  "path": "https://api.myklick.local/app/post/home",
  "per_page": 5,
  "prev_page_url": null,
  "to": 7,
  "total": 0
}

taylorotwell added a commit that referenced this issue Oct 7, 2021
* Add failing test

* Fix issue #535

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
@driesvints
Copy link
Member

This'll be in next week's release. Thanks @mmachatschek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants