0

My code is here: https://github.com/Dyfused/ExplodeX/blob/master/labyrinth-mongodb/src/main/kotlin/explode2/labyrinth/mongo/LabyrinthMongo.kt#L87,L259

document structures

Set example:

{
  "musicName": "Ignotus Afterburn",
  "musicComposer": "Arcaea Sound Team",
  "introduction": "yay",
  "coinPrice": 0,
  "noterName": "official",
  "noterUserId": "f6fe9c4d-98e6-450a-937c-d64848eacc40",
  "chartIds": [
    "l54uw6y79g1pspqcsvok31ga"
  ],
  "publishTime": {
    "$date": {
      "$numberLong": "1640966400000"
    }
  },
  "category": 0,
  "hidden": false,
  "reviewing": false
}

GameRecord example:

{
  "playerId": "92623248-b291-430a-81c5-d1175308f902",
  "playedChartId": "qsx8ky1c94f9ez1b8rssbsr2",
  "score": 994486,
  "detail": {
    "perfect": 1308,
    "good": 7,
    "miss": 1
  },
  "uploadTime": {
    "$date": {
      "$numberLong": "1"
    }
  },
  "r": 0
}

Program logic

When the sort type is 'DESCENDING_BY_PLAY_COUNT', it just stuck and return something seemed to be wrong.

Line 101 to 234 is just filtering, it have nothing to do with sorting.

I want to sort the sets by the related records count. So I firstly 'lookup' the related records then get the size of the related records. But it seemed has a heavy efficient problem, which I cannot figure out how to resolve.

Relevant pipeline additions:

SearchSort.DESCENDING_BY_PLAY_COUNT -> {
    pipeline += lookup("GameRecords", "chartIds", "playedChartId", "playRecords")
    pipeline += addFields(Field(
                    "playCount",
                    MongoOperator.size.from("\$playRecords")
                ))
    pipeline += sort(descending(SongSetWithPlayCount::playCount))
}
rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
Taskeren
  • 35
  • 3
  • Do you have an index on `"playedChartId"`? I'm also wondering if you include a pipeline in the `"$lookup"` and project only `"_id"` or `"playedChartId"`, perhaps it might be faster. – rickhg12hs Jan 15 '23 at 11:49

0 Answers0