In my application players can create and join games. I store every game in a mapping(uint => Game), and send out a GameCreated event whenever a game is created. My issue is efficiently getting a list of open (not yet joined) games on the client side.
I could iterate through all Game objects and filter out those that have been joined, but this is not scalable. At first I thought that listening for GameCreated events would help, but I'd still have to filter out using GameJoined events, since I don't think I can modify logs that have been logged already. This has the same scalability issue. I could mitigate it by only getting logs from the past week or whatever, but I don't really like this option.
I considered making a dynamically sized array where each item is the game id of an open game, but in order to update this list I'd need to be able to delete entries when a game was joined, which would require storing the index in each Game object. But then when an entry was deleted, all those other game objects would need to be updated with the new index and it's just a mess.
Ideally this application will get a lot of traffic some day, so I kind of need an efficient solution. Is there something obvious I'm missing here? Are there any better workarounds you've come across? I wish I could iterate through a mapping with only the currently open games, but I don't think that's possible.