PasTim wrote: 
> I have, on very rare occasions (I think only when completely resetting
> LMS), seen the id numbers increase, and rather than rescanning I have
> changed the ids back to where they were (1 and 2 on my system).

I think I might have identified the issue, unfortunately I think it’s a
reasonably big issue and I’m a bit surprised that it works predictable 
for anyone after a full rescan.

As the logic works the multilibrary_libraries.id values is reused as
long as a matching multilibrary_libraries.libraryid is found in the
table. This means that id should never change purely due to an upgrade,
new/changed files rescan or playlist rescan. However, if the contents of
library.db is cleared, which happens in a full rescan or a new
installation, the libraries will be re-created from scratch and when
this happens they can potentially get new ids. As long as
multilibrary_libraries table isn’t cleared the libraries should keep
their id.

The order the libraries are recreated will affect which library that
gets the lowest and highest id. This order is unfortunately very
unpredictable as it’s just the order of the hash in the following
for-loop:
https://github.com/erland/lms-multilibrary/blob/28d437d83235aceaac6e47b389727d46488de139/src/Plugin.pm#L326
Sorting the hash keys would make it a bit more predictable but it would
not be a solution since creating a new library with a file name that’s
alphabetically in the middle of existing libraries would cause itself
and the libraries after it to get a new id after next rescan.

I’m also not 100% sure the AUTOINCREMENT id column always is reset so
the first library created gets id 1. If library.db is completely deleted
it probably will but I don’t remember exactly how this is handled in the
full rescan. If AUTOINCREMENT is reset to 1 during a full rescan and the
hashing order hasn’t been changed due to Perl upgrade or similar, the id
would probably be the same after each full rescan. But the hash order is
very undefined and can likely change due to other things than Perl
version, so I really think it’s pure luck that this works reliable for
anyone with more than a single library.

If someone deletes a library and re-creates it, it will likely get a
higher id and after next full rescan the id will be decreased if
AUTOINCREMENT results in id starting from 1 again. 

So to sum it up, I have to admit that the implementation is really a
mess and I’m surprised I didn’t notice it myself when implementing the
plugin.

A solution to this really need to store an id in either the library
configuration file or in the prefs file of each library and replace the
AUTOINCREMENT column with a manually updated integer and make sure to
take the value from prefs/library configuration when creating the row in
multilibrary_libraries table, which happens here:
https://github.com/erland/lms-multilibrary/blob/28d437d83235aceaac6e47b389727d46488de139/src/Plugin.pm#L352
It’s probably easiest to store Id in prefs because then it can be
completely handled in initDatabaseLibrary function and doesn’t have to
affect other parts of the code.

Just wrote the above if someone wants to try to fix the problem and
release a new version of the plugin. Personally I’d still advice people
that have the possibility to switch to the built-in virtual libraries
functionality rather than using the currently unsupported Multi Library
plugin. Of course, switching to built-in virtual library functionality
won’t work for everyone since they rely on functionality in Custom
Browse and SQL Playlist plugins which currently doesn’t support virtual
libraries.

I wish I had the time to fix my own mess but unfortunately other things
in my life (family, day work) is currently more important so it’s
unlikely to happen in the foreseeable future, really sorry for this. If
someone else wants to fix it and distribute a new plugin version I’m
happy to try to answer any questions or review smaller code changes.



Erland Isaksson ('My homepage' (http://erland.isaksson.info))
Developer of 'many plugins/applets'
(https://wiki.slimdevices.com/index.php/User_Erland.html)
*Starting with LMS 8.0 I no longer support my plugins/applets* ('see
here for more information'
(https://forums.slimdevices.com/showthread.php?49483-Announce-New-versions-of-erlands-plugins&p=998836&viewfull=1#post998836)
)
------------------------------------------------------------------------
erland's Profile: http://forums.slimdevices.com/member.php?userid=3124
View this thread: http://forums.slimdevices.com/showthread.php?t=49483

_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to