leonhard-s / auraxium

A high-level Python wrapper for the PlanetSide 2 API.
https://auraxium.readthedocs.io/
MIT License
28 stars 8 forks source link

Add call-soon utility #27

Closed leonhard-s closed 1 year ago

leonhard-s commented 3 years ago

When working with websocket data, it is common to have a barrage of similar responses sent to the REST API all the time, like when resolving experience IDs or character names.

For these time-insensitive use-cases, it would be better to bundle these requests depending on their URL and query as part of a single, larger query.

A few notes on implementation:

There were plans for the proxy system to take on similar capabilities at one point. We should make sure this does not overlap with the new proxy system (#22) too much.

leonhard-s commented 1 year ago

Closing due to low demand. Users seeking this functionality can use pattern like the following to support these types of lazy lookups:

import auraxium
from auraxium import event, ps2

async def main() -> None:
  async def auraxium.Client(...) as client:

    char_id_cache: list[int] = []

    @trigger(event.Death)
    async def on_death(evt: event.Death) -> None:
        char_id_cache.append(evt.character_id)

        if len(char_id_cache) > 100:
          chars = client.find(ps2.Character, character_id=','.join(map(str, char_id_cache)))
          do_stuff_with_chars(chars)
          char_id_cache.clear()