Ok... Before I do any more work on this...
I have found that some fairly major modifications were in order to re-factor the code when trying to incorporate counts. I think I have managed to get my head around the way everything was working before, so I have taken some liberties that I hope are appreciated. But before I go any further I was hoping someone might take a look at this and let me know if I'm going down the right path - or not...
This is a copy of my CVideoDatabase::GetNavCommon(). Im waiting on further guidance before attacking GetPeopleNav, GetYearsNav, etc.
http://pastebin.com/ysXCkqAp
The gist of the approach I took:
1. Since getting counts requires doing group bys anyway, there seemed to be little to be gained doing an entirely separate code path for when source lock checks were needed, so the branch for lock checking is happening much further into the routine and is much more granular. The same queries are used regardless of whether or not the checks are needed.
2. The old code essentially returned 1 row per id (id as in the grouping id, genre, studio, etc.) for the normal path and 1 row per item for the lock check path (in order to check the source paths). The new code does 1 row per source path by using a group by on the id and the path.idpath, and handles the duplicate ids in code using the map. (hope that makes sense... The code reads fairly straightforward to me, but I wrote it
)
3. I added playcount support for tvshows. It seemed appropriate to do so since the way the code is factored now it will work. It is actually a count of episodes, not shows - but that seems more useful anyway. When you go a level deeper the counts "split" by tv show, so it is obvious what is happening from a user perspective.
I find the new code easier to understand, but there "may" be a performance hit when there is no need for lock checking due to the query now being a bit more complex. It seemed like a good tradeoff to me though.
Also, I did notice something else while working on this. I thought I caused it, but after digging deeper it was already there. Set handling doesn't work quite right (or maybe I should say it doesn't work the way I would have expected).
For example: If you have 3 movies in a set, and one is genre "action" but the other 2 are not. When you go to genres the one movie that matches will be counted. But when you click into the next level of the hierarchy, the entire set is returned. Also, if you have 1 movie in a set (which I admit makes little sense, but I did it just to test), for some reason it doesn't show up in the listing at all... I have not figured out what is causing this - but it isn't my code, it appears it already had this issue.
The more I play with it the more it seems to make sense to just disable displaying sets as a folder underneath the "special" nodes - it never worked right anyway, but with the counts it is painfully obvious now that it doesn't work right...