artemis/core
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
..
adb_handlers fix generated keychip validation failures 2024-09-09 16:53:14 +00:00
data use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
templates frontend: "Edit Card" -> "Card Information" 2024-08-09 02:43:39 -04:00
__init__.py Fix --config option not being respected, fixes #172 2024-09-06 10:36:57 -04:00
aimedb.py aimedb: add warning for all-zero access code/idm 2024-07-18 13:30:46 -04:00
allnet.py ongeki: fix frontend versions 2024-06-09 03:14:43 -04:00
app.py Fix --config option not being respected, fixes #172 2024-09-06 10:36:57 -04:00
config.py use SQL's limit/offset pagination for nextIndex/maxCount requests (#185) 2024-11-16 19:10:29 +00:00
const.py update keychip serial generation code 2024-07-09 15:10:42 -04:00
frontend.py frontend: implement add/edit card 2024-08-09 02:37:34 -04:00
mucha.py mucha: UTC_SERVER_TIME -> SERVER_TIME_UTC 2024-02-24 16:49:02 -05:00
title.py update get_mucha_info documentation 2024-05-19 21:40:02 -04:00
utils.py fix: make database async 2024-11-14 12:36:22 +07:00