Lots of new code here, most of this is from a post on forums:
Things to do:
A few bits of tidy up refactoring, eg CVideoDatabase::GetValueString's 2
versions could do with their core being merged.
Style/whitespace probably isn't quite right
Some of the funcs could probably do with better names
Some docs on how the Update works, as it's rather tied into being called
Testing - at the moment I've done some basic testing, but really need to
check that the api works in all cases.
Note the focus is for the available calls from the JSON VideoLibrary.
How does it work:
During the parsing in UpdateVideoTag of the JSON items into the existing
object, a vector of changed items is made.
To try and make the code more readable I've converted the long list of
If's into calls to new wrapper funcs (also called UpdateVideoTag) The
simple wrappers checks that the current value is differnt to the new
value, and only flags it for update, complex lists are always updated.
I'm not happy with how many versions of UpdateVideoTag there are, I
can't escape the feeling some kind of generic would be better, however,
there's no generic conversion on CVariant.
The idea is that the JSON provides the vector of changes into a new API
in the VideoDatabase code.
The new API is called:
It takes the same params as SetDetailsForMovie, along with the vector of
The first it does it take the vector and convert it into two lists,
handled by PendingUpdates.
One is a list of the simple changes (in fact a list of VIDEODB_ID enum
values). This list is checked for types that I guess have changed into
lists, eg genre, directors, although they were once their own field in
the db. This simple list is used to create the UPDATE SQL call.
The more complex list contains harder to parse items, eg art and tags.
If it doesn't understand one of the changes it falls back to using the
The update work then tries to only do the needed updates. It starts
with the simple updates, and processes the lists, eg Genre, director,
studios, and deletes the db entries and adds them back in.
It them moves onto the tags and art, and processes them in the same way,
IE only deletes them if needed.
The last part is the SQL Update. I've added a new version of
GetValueString, which takes the vector of "simple" changes, and will
generate an update of just the items that have changed.
If nothing needs an "UPDATE" one won't be run.
Split artwork changes into altered and removed.
Add some log messages to allow for better timing.
In SetArtForItem only update an item of art if the url has actually
changed. Saves a number of extra round trips.
Remove code that set the lastplayed and playcount to match any other
found copy of the movie. It doesn't seem to make sense to do so during
an update, as the update requires the file already exists, so it's not a
If 300+ updates are carried out too quickly then the message loop
struggles with the refresh events from the Json layer.
It appears that the JSON layer triggers a full refresh, and this causes
pain if you're on the movies view as the refreshes process.
I've added an extra API to allow a FileItem to passed into the refresh
builder, and it then passes that item around as being the thing to
This stops the heavy refresh rate, but still slows the UI down while it
gets through the backlog of events.
I've also added code to only push a refresh event if there was actually
a change to the movie.