Jump to content

New Plugin - Devices Database Cleaner


chef

Recommended Posts

I made this plugin quickly today because I was having issues with certain client application swamping my device lists.

 

As you can see from the image below:

 

5e0957578723d_deviceFixPlugin2.png

 

 

The plugin will list and group all your devices saved in the Emby Database:

 

WOW! 1394 versions of Chrome saved in the Database! Let's remove the old and insignificant  ones using this plugin.

 

 

5e095799c7f00_deviceFixPlugin.png

 

 

Okay, now there is only one version of Chrome, which is the Client Session that is being currently run (the plugin skips over any sessions that are currently in use - We don't want to kick anyone off the server inadvertently).

 

 

5e0957ea5728a_deviceFixPlugin3.png

 

 

This is better, and the Devices page loads instantaneously after doing a little bit of browser cache clearing.

 

5e095c97b4bac_deviceFixPlugin5.png

 

 

Note: See how quickly Chrome tricks Emby into thinking it is a new Device Connection! Holy COW three more just added themselves since the clean up!  

 

The console will list the removed device ids in red

 

5e0a5a4709508_devFixPlugin6.png

 

There is a user dialog which allows for custom threshold limits with regards to what is considered too many devices stored.

 

5e0a5a74edbad_devFixPlugin7.png

 

 

Fixes:

-Plugin is satisfied with the amount of clients logged in the database and didn't know what do. Now it does.

-Added User input Threshold limit dialog

-Device removal will show in red inside the browser console - these are not errors, it it's to confusing I'll change the color to hot pink.

 

 

Possible Future Updates:

1. Create a Scheduled task that will be customizable to remove specific  clients automatically that are a certain age.

2. User will be able to set the threshold for what is considered "TOO MANY INSTANCES!" (Currently set to 25 instances)

3. Update Plugin UI when Devices are removed from the Database. (There is currently no UI updating - Press the Get Devices List - Button)

4. Make it pretty or something (right now it is utility, and there is no time to make it pretty).

 

 

DOWNLOAD: DeviceEditor.zip

Edited by Happy2Play
updated link
  • Like 10
  • Thanks 3
Link to comment
Share on other sites

Happy2Play

Plugin Displayed name may need updating "Copy and Decompression".

 

Don't know is beta server makes a difference, but all I get is the spinning circle when trying to get device list. Only 18 devices appear via Dashboard-Devices.  Don't really see anything in the server log.

  • Like 1
Link to comment
Share on other sites

Plugin Displayed name may need updating "Copy and Decompression".

 

Don't know is beta server makes a difference, but all I get is the spinning circle when trying to get device list. Only 18 devices appear via Dashboard-Devices.  Don't really see anything in the server log.

 

 

I found the issue, thanks for that @@Happy2Play

 

What happens when the plugin is satisfied that there isn't an abundance of extra clients in the Database?

 

A spinning circle.

 

 

Will fix immediately. 

Edited by chef
  • Like 1
Link to comment
Share on other sites

Happy2Play

Are there any errors in the browser console by chance? Could be a beta thing, ApiClient is only requesting  "Devices" endpoint.

 

Sometimes it can take a while to return a large list. But 18 shouldn't take long.

 

Ah, right... Copy and Compression, my goto copy paste plugin code.

 

Yes

configurationpage?name=DeviceEditorConfigurationPageJS&v=4.4.0.4:81 Uncaught (in promise) ReferenceError: i is not defined
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.4.0.4:81
    at Map.forEach (<anonymous>)
    at createDeviceGroups (configurationpage?name=DeviceEditorConfigurationPageJS&v=4.4.0.4:59)
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.4.0.4:124
note I see the same on stable 4.3.1.0 Edited by Happy2Play
  • Like 1
Link to comment
Share on other sites

Fixed it, and re-posted to the OP download link.

 

Didn't think about making the plugin satisfied with conditions, and the "i" was a counter which was for the console.

 

Thank you again.

Edited by chef
Link to comment
Share on other sites

Happy2Play

I don't see any change in the updated plugin.  And on my stable server I have over 100 devices listed and get the same results.

Uncaught (in promise) ReferenceError: i is not defined
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:81
    at Map.forEach (<anonymous>)
    at createDeviceGroups (configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:59)
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:124

Does this plugin work for anyone else or is it just me?

  • Like 1
Link to comment
Share on other sites

I don't see any change in the updated plugin.  And on my stable server I have over 100 devices listed and get the same results.

Uncaught (in promise) ReferenceError: i is not defined
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:81
    at Map.forEach (<anonymous>)
    at createDeviceGroups (configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:59)
    at configurationpage?name=DeviceEditorConfigurationPageJS&v=4.3.1.0:124

Does this plugin work for anyone else or is it just me?

 

@@Happy2Play

 

I've double checked the instance of the "i" counter in the javascript and put a new build at the top..

 

Because the plugin version doesn't  change for each build, it is possible that the browser would have cached the original code and will have to be cleared.

 

 

This was the first time I wrote a plugin where 90% of the conditions are figured out on the front end in the javascript instead of in the code behind.  I think that is why those console errors for 'i' are not disappearing.

 

Looking forward to seeing how you make out with all of those devices in the list.

Link to comment
Share on other sites

Happy2Play

@@Happy2Play

 

I've double checked the instance of the "i" counter in the javascript and put a new build at the top..

 

Because the plugin version doesn't  change for each build, it is possible that the browser would have cached the original code and will have to be cleared.

 

 

This was the first time I wrote a plugin where 90% of the conditions are figured out on the front end in the javascript instead of in the code behind.  I think that is why those console errors for 'i' are not disappearing.

 

Looking forward to seeing how you make out with all of those devices in the list.

Clearing the browser cache resolved the issue.  I end up with Chrome 45 devices and a Fix it button but the button doesn't do anything for me. alone with all the other named devices listed.  No logging or console errors.

Edited by Happy2Play
  • Like 1
Link to comment
Share on other sites

Clearing the browser cache resolved the issue. I end up with Chrome 45 devices and a Fix it button but the button doesn't do anything for me. alone with all the other named devices listed. No logging or console errors.

If you refresh the browser page and then press the button again, does it show a smaller list?

 

The UI doesn't update, in that version, so it has removed devices from the database but it can't let you know about it yet. I fixed it in the OP download.

 

Now the plugin will remove all the HTML and have the user press the button again to retrieve updated info.

 

With all the JavaScript promises this was the easiest way to update the configuration html.

 

The only other thing is the Emby devices menu doesn't update its list of devices without a media scan and a browser cache clear.

 

Not sure how to handle that. Might just have to let emby do its thing and users will have to be patient with their device page.

Edited by chef
Link to comment
Share on other sites

Nice work @@chef.

 

You can't actually delete devices via the plugin yet, as not seeing the FIX IT button on my server?

Hey thanks @@CBers, the fix it button will only appear if there are over 25 instances of the same client.

 

Do you have a device group with more then 25 items?

 

I do have a version here that will allow for the user to change the threshold.

Link to comment
Share on other sites

Added user defined threshold limit dialog

 

Also lists the removed devices in the console.

 

If the plugin has older versions of itself installed - after adding the new version in the OP download, rerstart server and clear the browser cache to make the browser honer the new javascript code.

Edited by chef
  • Like 1
Link to comment
Share on other sites

Happy2Play

Added user defined threshold limit dialog

 

Also lists the removed devices in the console.

 

If the plugin has older versions of itself installed - after adding the new version in the OP download, rerstart server and clear the browser cache to make the browser honer the new javascript code.

 

 

Newest version worked. 

 

Ideally I would envision devices be automatically removed after X days of inactivity.

Edited by Happy2Play
Link to comment
Share on other sites

Newest version worked.

 

Ideally I would envision devices be automatically removed after X days of inactivity.

Perfect, I finished a hidden scheduled task which will run automatically every night and will look at devices dates and remove them based on user defined time spans.

 

If that works out, is it worth requesting a catalogue entry, or maybe it's more of a 'leave it in the threads' plugin?

Link to comment
Share on other sites

CBers

Added user defined threshold limit dialog

 

Where is this setting please?

 

Can't see it in the plugin, even after clearing browser cache and restarting Emby.

Link to comment
Share on other sites

Where is this setting please?

 

Can't see it in the plugin, even after clearing browser cache and restarting Emby.

There should be a gear icon at the top, that will open a dialog with the option.

Link to comment
Share on other sites

Happy2Play

Perfect, I finished a hidden scheduled task which will run automatically every night and will look at devices dates and remove them based on user defined time spans.

 

If that works out, is it worth requesting a catalogue entry, or maybe it's more of a 'leave it in the threads' plugin?

Personally I would like to see this added to the catalog for potential update purposes.

Link to comment
Share on other sites

I have a scheduled task all laid out, but unfortunately there is no easy way to remove devices in the IDeviceManager object in the code behind.  :(

 

In order to remove a device, an IHttpClient (in the plugin) has to be created and authorized, which would create another device under embys Devices tab for the plugin. this seems counter productive.

 

There is an IAuth service which might lead to a quick way to create an api_key to make requests, but I'm not sure.

 

We'll have to wait on the scheduled task.

 

 

Link to comment
Share on other sites

Happy2Play

I have a scheduled task all laid out, but unfortunately there is no easy way to remove devices in the IDeviceManager object in the code behind.  :(

 

In order to remove a device, an IHttpClient (in the plugin) has to be created and authorized, which would create another device under embys Devices tab for the plugin. this seems counter productive.

 

There is an IAuth service which might lead to a quick way to create an api_key to make requests, but I'm not sure.

 

We'll have to wait on the scheduled task.

 

No worries this is a good start.  Are you seeing any issues with the Threshold limit setting as it doesn't appear to do anything to me?

 

To me the server should automatically remove devices that are inactive after X days in my opinion though.

  • Like 1
Link to comment
Share on other sites

@@Happy2Play

 

I think I figured out that issue.  Now when the "OK" button is pressed in the settings Dialog the device groups are removed from the page and the "Get Device List" button is brought to the top of the page again.

 

After pressing the button, the threshold should be honored.

 

I've updated the Download.

Link to comment
Share on other sites

Happy2Play

@@Happy2Play

 

I think I figured out that issue.  Now when the "OK" button is pressed in the settings Dialog the device groups are removed from the page and the "Get Device List" button is brought to the top of the page again.

 

After pressing the button, the threshold should be honored.

 

I've updated the Download.

Progress, but I don't see a Okay button in Chrome but do in FireFox.  So setting it in FireFox saved the setting and was honored in Chrome.

 

Looks like it is related to system Display Scaling.  If not at 100% it pushes button out of view.  Well my stable is not scaled and was still out of view in dialog box.  Had ot set browser zoom to 80% to see.

Edited by Happy2Play
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...