artemis/titles/chuni
beerpsi 58a5177a30 use SQL's limit/offset pagination for nextIndex/maxCount requests (#185)
Instead of retrieving the entire list of items/characters/scores/etc. at once (and even store them in memory), use SQL's `LIMIT ... OFFSET ...` pagination so we only take what we need.

Currently only CHUNITHM uses this, but this will also affect maimai DX and O.N.G.E.K.I. once the PR is ready.

Also snuck in a fix for CHUNITHM/maimai DX's `GetUserRivalMusicApi` to respect the `userRivalMusicLevelList` sent by the client.

### How this works

Say we have a `GetUserCharacterApi` request:

```json
{
    "userId": 10000,
    "maxCount": 700,
    "nextIndex": 0
}
```

Instead of getting the entire character list from the database (which can be very large if the user force unlocked everything), add limit/offset to the query:

```python
select(character)
.where(character.c.user == user_id)
.order_by(character.c.id.asc())
.limit(max_count + 1)
.offset(next_index)
```

The query takes `maxCount + 1` items from the database to determine if there is more items than can be returned:

```python
rows = ...

if len(rows) > max_count:
    # return only max_count rows
    next_index += max_count
else:
    # return everything left
    next_index = -1
```

This has the benefit of not needing to load everything into memory (and also having to store server state, as seen in the [`SCORE_BUFFER` list](2274b42358/titles/chuni/base.py (L13)).)

Reviewed-on: https://gitea.tendokyu.moe/Hay1tsme/artemis/pulls/185
Co-authored-by: beerpsi <beerpsi@duck.com>
Co-committed-by: beerpsi <beerpsi@duck.com>
2024-11-16 19:10:29 +00:00
..
img new chuni ui images/directories 2024-11-03 08:48:13 -05:00
schema use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
templates hardened ui against the db not being upgraded or importer not being ran 2024-11-08 09:17:12 -05:00
__init__.py chuni: add frontend 2024-01-12 18:03:11 -05:00
air.py begin move 2024-01-09 03:07:04 -05:00
airplus.py begin move 2024-01-09 03:07:04 -05:00
amazon.py begin move 2024-01-09 03:07:04 -05:00
amazonplus.py begin move 2024-01-09 03:07:04 -05:00
base.py use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
config.py Added customization unlock overrides 2024-11-03 19:12:49 -05:00
const.py use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
crystal.py begin move 2024-01-09 03:07:04 -05:00
crystalplus.py begin move 2024-01-09 03:07:04 -05:00
database.py [chuni] Frontend favorites support (#176) 2024-09-25 14:53:43 +00:00
frontend.py hardened ui against the db not being upgraded or importer not being ran 2024-11-08 09:17:12 -05:00
index.py chuni: fix encryption , and added all known iter keys 2024-07-10 07:17:12 +00:00
luminous.py [chuni] Use the map flag event ID when checking in GetGameMapAreaConditionApi 2024-06-23 01:36:48 +07:00
new.py use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
newplus.py begin move 2024-01-09 03:07:04 -05:00
paradise.py begin move 2024-01-09 03:07:04 -05:00
plus.py begin move 2024-01-09 03:07:04 -05:00
read.py db and import updates for userbox, avatar, voice, and map icon 2024-11-03 16:37:05 -05:00
star.py begin move 2024-01-09 03:07:04 -05:00
starplus.py begin move 2024-01-09 03:07:04 -05:00
sun.py chuni: added missing c2c endpoint for sdgs 2024-07-10 07:21:56 +00:00
sunplus.py begin move 2024-01-09 03:07:04 -05:00