zixaphir / Stable-Diffusion-Webui-Civitai-Helper

Stable Diffusion Webui Extension for Civitai, to manage your model much more easily.
175 stars 24 forks source link

[Feature] Better download handling with step-back (503s, etc.) #62

Closed Godsfoot closed 1 month ago

Godsfoot commented 6 months ago

This extension is an amazing asset and I use it routinely, but as the popularity of Civitai grows, it seems the stability of their website has suffered, likely due to the increase in demand and an increase in complexity of the overall site itself.

As a side-effect it seems the likelihood of requests to their APIs returning 503 errors or other error codes has also increased. I think this extension should implement some configurable settings to allow users to control how resilient to instability they want it to be before giving up.

This should be a fairly small change to the 'downloader.py' and then exposing them as configurable settings in the UI.

Proposed Changes:

I quickly modified 'downloader.py' locally to test my theory and with >1000 models being scanned and multiple periods of 503 outage it continued.

DL_EXT = ".downloading"
MAX_RETRIES = 30
INITIAL_RETRY_DELAY_S = 0

...

def request_get(
    url:str,
    headers:dict | None=None,
    retries=0,
    retry_delay=INITIAL_RETRY_DELAY_S
) -> tuple[Literal[True], requests.Response] | tuple[Literal[False], str]:

...

        if status_code != 404 and retries < MAX_RETRIES:
            util.printD("Retrying")

            # Step-back delay (could look into threading event sleeps)
            time.sleep(retry_delay)

            # Recursively call with an increased delay time (naive +3s each time, could make smarter) 
            return request_get(url, headers, retries + 1, retry_delay + 3)

...
zixaphir commented 6 months ago

Can you send your changes as a pull request to the dev branch?

Godsfoot commented 5 months ago

Not being a proficient extension writer/python dev, I opted to keep it simple but functional, and you can look towards improving it/making it customizable later.

Here is a basic PR for an initial implementation: https://github.com/zixaphir/Stable-Diffusion-Webui-Civitai-Helper/pull/72

zixaphir commented 1 month ago

This was merged awhile back. I apologize for not updating this issue