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

Max pages bug causes search to fail (tested with Gelbooru) #30

Open
hakaserver opened this issue Apr 30, 2024 · 1 comment
Open

Max pages bug causes search to fail (tested with Gelbooru) #30

hakaserver opened this issue Apr 30, 2024 · 1 comment

Comments

@hakaserver
Copy link
Contributor

hakaserver commented Apr 30, 2024

When setting 'Max Pages' has a minimum accepted value of 1, and when setting to 1 page the final url it generates to search has the parameter pid=1. However the first page should be pid=0.
This causes the extension to never be able to find the first 100 images for any tag searched.
This is a problem when the tags searched returns less than 100 images (such as some artist tags, character tags and more obscure general tags).

Also, when using the ComfyUI node version of the extension I didn't find any way to set 'Max Pages', which causes the search to frequently fail.

In addition to that, I'd like to suggest an alternative:
Instead of manually inputting 'Max Pages', make an initial search with pid=100 and lookup the number of search results ('count' as seen below).

{
  "@attributes": {
    "limit": 100,
    "offset": 100,
    "count": 375
  }

Using the count number you can calculate 'Max Pages' based on how many results per page there is.

@hakaserver
Copy link
Contributor Author

Made a pull request #31.

In the first commit:

  • Made some changes that fixes the bug of the first page never being considered in the randomization.
  • Also made changes to fix another bug, when the number of results is less than the POST_AMOUNT = 100.

In a separate second commit:

  • Modified get_data functions to loop once if the number of search results are fewer than max_pages*POST_AMOUNT (100 results per page).
  • The second time the get_data function runs it uses a max_pages value small enough to return the results.

With these changes, it should all work correctly even with few results, as long as there is 1 search result.
I made the changes in 2 separate commits since the loop once implementation was the best I could come up with, in case you have a better or cleaner way of doing it.

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

No branches or pull requests

1 participant