I
Immich•2y ago
bubter

Immich API getRandom returns empty list

in the documentation it mentions the getRandom api endpoint. However, when I make an api call, it returns an empty list. Has this functionality been implemented yet?
35 Replies
Alex Tran
Alex Tran•2y ago
Can you post the actual request?
bubter
bubterOP•2y ago
The curl command i am using is right out of the documentation: curl -L -X GET 'photos.hostname.com/api/asset/random?count=1' \ -H 'Accept: application/json' \ -H 'x-api-key: xxxxxxxxxxxxxxxxxxxx'
Alex Tran
Alex Tran•2y ago
Do you have any asset on your instance?
bubter
bubterOP•2y ago
yes, a little under 11 thousand
Alex Tran
Alex Tran•2y ago
😛
bubter
bubterOP•2y ago
all other api calls return expected results.
Alex Tran
Alex Tran•2y ago
Hmm I am seeing this as well
bubter
bubterOP•2y ago
At least, those that I have tried. including getAllAsset. So its not just my instance?
Alex Tran
Alex Tran•2y ago
yeah there might be a bug with that endpoint @Daniel Any thoughts on this? ah wait Can you try ?count=5? http://IP:2283/api/asset/random?count=1
bubter
bubterOP•2y ago
Same result.
Alex Tran
Alex Tran•2y ago
strange, if I put int ?count=<number> then it works for me which server version are you on? Can you try to make the request from the browser?
bubter
bubterOP•2y ago
I am on 1.79.1. I just tried through the web browser and i get the same thing.
Alex Tran
Alex Tran•2y ago
Can you update to 1.80 and try again? I believe there is a bug fix for this endpoint in 1.80
bubter
bubterOP•2y ago
Ok, it does now return a result when count=1, but only about 40% of the time.
Alex Tran
Alex Tran•2y ago
hmm really? confirmed this is weird can you help to file a bug report on GitHub?
bubter
bubterOP•2y ago
Sure.
Alex Tran
Alex Tran•2y ago
Thank you
bubter
bubterOP•2y ago
Bug report submitted.
Alex Tran
Alex Tran•2y ago
Appreciate it!
bubter
bubterOP•2y ago
Thank you.
Daniel
Daniel•2y ago
@bubter Hm this should really not be happening anymore. I'll have a look at it later Ok @bubter, unfortunately I'm not able to reproduce the issue. On version 1.80 I always get the exact number of assets specified by count, or one asset if count is not specified. The api key actually belongs to the user that owns the 11k assets? (or at least more than one)
SELECT *
FROM assets
OFFSET FLOOR(RANDOM() * (SELECT GREATEST(COUNT(*) - 1, 0) FROM ASSETS)) LIMIT 1;
SELECT *
FROM assets
OFFSET FLOOR(RANDOM() * (SELECT GREATEST(COUNT(*) - 1, 0) FROM ASSETS)) LIMIT 1;
Could you try running this as described here?
bubter
bubterOP•2y ago
The command returns a result every time. Yes, the api-key belongs to the correct user. Either way, there are no users with a blank library. Furthermore, this behavior is not limited to an api-key, as it has the same behavior when using my browser.
Daniel
Daniel•2y ago
Oh that's weird. The api basically only calls that query lol
bubter
bubterOP•2y ago
Thats.... intriguing. Could Nginx Proxy Manager somehow affect it? I don't see how/why it would return an empty list, but its the only thing between me and the server.
Daniel
Daniel•2y ago
You mentioned though that other api endpoints work for you, right?
bubter
bubterOP•2y ago
Yes, I have had no issues with other endpoints. Ok, I have just tried making the call using http and the host directly, no change.
jrasm91
jrasm91•2y ago
Do you have multiple users?
bubter
bubterOP•2y ago
yes. 4 in total, including admin.
jrasm91
jrasm91•2y ago
Do they all have assets?
bubter
bubterOP•2y ago
The admin does not, but the rest do.
jrasm91
jrasm91•2y ago
I'm guessing you are somehow using the admin id in the api call or query for some reason. If you want to verify, you can try this - change the start command for the postgres container to:
command: ["postgres", "-c", "log_statement=all"]
command: ["postgres", "-c", "log_statement=all"]
That will log all the queries. After a restart, hit the endpoint a few times and then send the logs over here. We can validate the params for the query are correct. Oh wait. Nope, this is a bug
bubter
bubterOP•2y ago
ok, I just uploaded a single asset to the admin account. No change.
jrasm91
jrasm91•2y ago
No description
jrasm91
jrasm91•2y ago
line 437 is filtering by owner id, but line 438 is doing an offset as a random number based on the total asset count. It should be SELECT COUNT(*) - $2, ... FROM ASSETS _WHERE ownerId = $1
Daniel
Daniel•2y ago
@bubter It should be fixed in 1.81.1

Did you find this page helpful?