Jump to content

Custom API - Database is locked (Docker host)


iRobie
Go to solution Solved by Luke,

Recommended Posts

iRobie

Hello!

 

What I'm doing is completely custom and no way at all related to the official Emby project. I recognize that and would appreciate any help that could be given!

 

I'm trying to write a custom API for Emby, in the vein of plexpy. Well, not that fancy.

 

I've had this working for over a year. The code is really simple: get recently played items from library.db userdata; get the clean name from that, search on ActivityLogEntries based on the CleanName, and tally up how much time has been spent watching each item.

 

As I said, this has been working. Now I'm getting database is locked when trying to query library.db. I close emby server, and this error goes away. 

 

I thought this was a php sqlite driver issue for a while, so I started re-writing the app in python. (Real API goal this time!). But I'm getting the same error.

 

 

I see the release notes on "3.2.18.0" include "Improve database performance". That's right about the time this error started. Did this include changing the locking mechanism on the DB?

 

For now I can work around this by copying the DB to a temp file, and querying that temp file. If there's a better option, I'd appreciate hearing about it!

 

Emby server Version 3.2.19.0

Docker image: emby/embyserver:latest

 

Thanks!

 

 

Link to comment
Share on other sites

  • Solution

Yea we open the database in exclusive mode. Why not just use the api?

  • Like 1
Link to comment
Share on other sites

iRobie

That explains it, thanks! It looks like exclusive mode gains a lot of performance, so I understand why this is the case.

 

I looked at the API, but I could only find how to get the clean name from the activity log. Correlating this to other items, like genres, was a no go. Looking at the userdata instead fixed this because I could get all info from the file first (including limiting the files to what's been played in X days), then use activitylog after that to match with the clean name.

 

I'm a mediocre coder at best, there might be a better way to achieve this. I'd rather not go the plexpy route of storing playstate in a separate database - querying the existing DB seems a lot easier.

Link to comment
Share on other sites

Well if you use the web api then you wouldn't need clean name because there are dedicated methods to get genres for an item. You can also just go with your hack of copying to a temp db. If you release something and it ends up with a sizable audience, then maybe we'll reconsider the locking mode. Thanks.

Link to comment
Share on other sites

iRobie

Do you have a recommendation for getting time spent watching an item?

 

The problem is the Activity Log doesn't have an item ID. /System/ActivityLog/Entries shows the clean name, but not the item object. Using the API does allow for getting genres, which solves my primary problem (thank you for the hint!). Here's my rough workflow:

 

  • Get recent activity from /System/ActivityLog/Entries
  • Get recently played items from Users/{UserID}/Items
  • For each played item, get play duration from activity, by searching the Activity Name field with contains(Item.Name)

 

Matching based on name contains is unreliable. For my personal uses this is close enough, but if I open this to others I'd want a more elegant solution. Do you have any recommendations?

 

Thank you again!

Link to comment
Share on other sites

I think what you will have to do is start with your name-based workaround, and then if interest in the project grows then we will support you by adding the new pieces of data that you need. 

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...