CHUNITHM - GetUserMusicApi returning duplicate songs #45

Closed
opened 2023-10-16 08:25:48 +00:00 by DSRLIN · 7 comments
Contributor

So after investigating the each return result of the api, i've noticed that some songs will be returned multiple times in these returns.


This seems would not cause any issue in game but some other services depends on this api might experience an issue while using the result directly.


I'm currently using a fix that use an global id set in ram, which clears after the nextIndex is given -1. This could solve the issue but I believe there are more elegant ways to do this.

So after investigating the each return result of the api, i've noticed that some songs will be returned multiple times in these returns. <br> This seems would not cause any issue in game but some other services depends on this api might experience an issue while using the result directly. <br> I'm currently using a fix that use an global id set in ram, which clears after the nextIndex is given -1. This could solve the issue but I believe there are more elegant ways to do this.
Collaborator

Hello DSRLIN,

If you have a better way of doing it, feel free to let us know a fix for the current code since I couldn't figure out something to permanently fix this

Thank you

Hello DSRLIN, If you have a better way of doing it, feel free to let us know a fix for the current code since I couldn't figure out something to permanently fix this Thank you
Author
Contributor
    def handle_get_user_music_api_request(self, data: Dict) -> Dict:
        music_detail = self.data.score.get_scores(data["userId"])
        if music_detail is None:
            return {
                "userId": data["userId"],
                "length": 0,
                "nextIndex": -1,
                "userMusicList": [],  # 240
            }

        song_list = []
        next_idx = int(data["nextIndex"])
        max_ct = int(data["maxCount"])

        for x in range(next_idx, len(music_detail)):
            found = False
            tmp = music_detail[x]._asdict()
            tmp.pop("user")
            tmp.pop("id")

            for song in song_list:
                score_buf = SCORE_BUFFER.get(str(data["userId"])) or []
                if song["userMusicDetailList"][0]["musicId"] == tmp["musicId"]:
                    found = True
                    song["userMusicDetailList"].append(tmp)
                    song["length"] = len(song["userMusicDetailList"])
                    score_buf.append(tmp["musicId"])
                    SCORE_BUFFER[str(data["userId"])] = score_buf

            score_buf = SCORE_BUFFER.get(str(data["userId"])) or []
            if not found and tmp["musicId"] not in score_buf:
                song_list.append({"length": 1, "userMusicDetailList": [tmp]})
                score_buf.append(tmp["musicId"])
                SCORE_BUFFER[str(data["userId"])] = score_buf

            if len(song_list) >= max_ct:
                break

        if len(song_list) >= max_ct:
            next_idx += len(song_list)
        else:
            next_idx = -1
            SCORE_BUFFER[str(data["userId"])] = []
        return {
            "userId": data["userId"],
            "length": len(song_list),
            "nextIndex": next_idx,
            "userMusicList": song_list,  # 240
        }

SCORE_BUFFER is a global empty dict in base.py and new.py.

```python def handle_get_user_music_api_request(self, data: Dict) -> Dict: music_detail = self.data.score.get_scores(data["userId"]) if music_detail is None: return { "userId": data["userId"], "length": 0, "nextIndex": -1, "userMusicList": [], # 240 } song_list = [] next_idx = int(data["nextIndex"]) max_ct = int(data["maxCount"]) for x in range(next_idx, len(music_detail)): found = False tmp = music_detail[x]._asdict() tmp.pop("user") tmp.pop("id") for song in song_list: score_buf = SCORE_BUFFER.get(str(data["userId"])) or [] if song["userMusicDetailList"][0]["musicId"] == tmp["musicId"]: found = True song["userMusicDetailList"].append(tmp) song["length"] = len(song["userMusicDetailList"]) score_buf.append(tmp["musicId"]) SCORE_BUFFER[str(data["userId"])] = score_buf score_buf = SCORE_BUFFER.get(str(data["userId"])) or [] if not found and tmp["musicId"] not in score_buf: song_list.append({"length": 1, "userMusicDetailList": [tmp]}) score_buf.append(tmp["musicId"]) SCORE_BUFFER[str(data["userId"])] = score_buf if len(song_list) >= max_ct: break if len(song_list) >= max_ct: next_idx += len(song_list) else: next_idx = -1 SCORE_BUFFER[str(data["userId"])] = [] return { "userId": data["userId"], "length": len(song_list), "nextIndex": next_idx, "userMusicList": song_list, # 240 } ``` SCORE_BUFFER is a global empty dict in base.py and new.py.
Author
Contributor

Just an ugly fix to this problem.

Just an ugly fix to this problem.
Collaborator

I'll test it out on Monday when i get some free time just to be sure it is working

To be honest, as long it works, i'm all up for it

I'll test it out on Monday when i get some free time just to be sure it is working To be honest, as long it works, i'm all up for it
Collaborator

Nvm i was able to test it just now but it ran into an undefined error with SCORE_BUFFER

I had to add SCORE_BUFFER = {} and that fixed it, running a test now on a few different profiles

Nvm i was able to test it just now but it ran into an undefined error with SCORE_BUFFER I had to add SCORE_BUFFER = {} and that fixed it, running a test now on a few different profiles
Collaborator

Hello,

From my testing, it appears to be working correctly so i think it should be good for a pull request for the develop branch

Just make sure that SCORE_BUFFER = {} is added underneath song_list = [] and it will be ready

Thank you!

Hello, From my testing, it appears to be working correctly so i think it should be good for a pull request for the develop branch Just make sure that SCORE_BUFFER = {} is added underneath song_list = [] and it will be ready Thank you!
Midorica added the
bug
chuni
chusan
labels 2023-10-24 15:18:05 +00:00
Midorica added the
testing
label 2023-10-24 15:22:44 +00:00
Collaborator

Hello DSRLIN,

Thank you for the referenced PR, i'll approve it as I also tested it personally without any issues, it fixed the weird bug we had before with scores that disappeared due to looped IDs.

Hello DSRLIN, Thank you for the referenced PR, i'll approve it as I also tested it personally without any issues, it fixed the weird bug we had before with scores that disappeared due to looped IDs.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Hay1tsme/artemis#45
No description provided.