I'm glad you pointed this out, I had been using Asphyxia and had the sense that something was wrong with my scores, but I thought it was failing to save at all, not overwriting scores every time.
I went through the exposed code like you have and made a very hacky solution. I think the real 'issue' is more to do with how it appears Asphyxia goes through the DDR DB file on launch and cuts out duplicate entries, but always keeps the latest. But that's just a guess, I didn't go through Asphyxia's code, I just assumed it would be out of my depth and I'd more quickly invent a fix on the plugin side.
I'm confident my solution is a bad hack and it may have consequences I haven't seen yet, but from my limited messing around, it works. Beneath line 207 in usergamedata.ts, insert the following block:
const scores = await DB.Find<Score>(refId, { collection: "score" });
let newHigh = false;
let found = false;
for (const sc of scores) {
if (sc.songId == songId && sc.difficulty == difficulty) {
found = true;
if (sc.score < score) {
newHigh = true;
}
}
}
if (newHigh || !found) {
(...upsert blocks...)
}
Make sure to put the final if statement above the two following upsert blocks, and close the bracket after them. This way, the upserts will not fire unless a score exists and is lower than the score you are trying to save. I don't know if my check that the song exists is necessary, but I was worried this doesn't work correctly if you are beating a song for the first time and thought I'd just toss it in there.