Skip to content

fix unnecessary time delay in get_version_list#1

Closed
v-pun215 wants to merge 1 commit intoJakobDev:masterfrom
v-pun215:master
Closed

fix unnecessary time delay in get_version_list#1
v-pun215 wants to merge 1 commit intoJakobDev:masterfrom
v-pun215:master

Conversation

@v-pun215
Copy link

This function here:

def get_version_list() -> list[MinecraftVersionInfo]:
    """
    Returns all versions that Mojang offers to download

    Example:

    .. code:: python

        for version in minecraft_launcher_lib.utils.get_version_list():
            print(version["id"])
    """
    vlist: VersionListManifestJson = get_requests_response_cache("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json").json()
    returnlist: list[MinecraftVersionInfo] = []
    for i in vlist["versions"]:
        returnlist.append({"id": i["id"], "type": i["type"], "releaseTime": datetime.fromisoformat(i["releaseTime"]), "complianceLevel": i["complianceLevel"]})
    return returnlist


sorts through the whole list and changes iso format of releaseTime to a datetime.datetime function. This is unnecessary as if an user requires this, they may get the version THEN change the releastTime to datetime.datetime.

This fixes a huge time delay that goes from 75.22 seconds to 0.26 seconds.

import minecraft_launcher_lib as mc
import time

start = time.time()

version_list = mc.utils.get_version_list()
print(version_list)

end = time.time()
print(f"Time taken: {end - start:.2f} seconds")

Output:

Screenshot 2025-07-31 at 6 18 01 PM

@github-actions
Copy link

This Repo is just a mirror of the Codeberg Repo. PRs arren't acceptet here. Please make a PR against the Codeberg Repo. It works the same Way as in GitHub. You can use your GitHub Account to login into Codeberg.

@github-actions github-actions bot closed this Jul 31, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant