SpigotMC / XenforoResourceManagerAPI

Exposes resource/author information via a simple JSON REST API
BSD 3-Clause "New" or "Revised" License
79 stars 7 forks source link

Authors not found (404) even though they exist #21

Closed InventivetalentDev closed 4 years ago

InventivetalentDev commented 4 years ago

A lot of authors return 404s via the API, even though both their resource overview and profile page exist and are publicly accessible.

Possibly related to #17

A few examples:

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=45870 => https://www.spigotmc.org/resources/authors/45870/

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=797245 => https://www.spigotmc.org/resources/authors/797245/

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=800551 => https://www.spigotmc.org/resources/authors/800551/

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=798575 => https://www.spigotmc.org/resources/authors/798575/
MiniDigger commented 4 years ago

they all don't have identities, maybe thats it?

InventivetalentDev commented 4 years ago

Yeah, was thinking the same. Looks like it's doing an inner join on 3 tables, including the one seemingly containing the identity info, so it might just skip everyone without identity info.
https://github.com/SpigotMC/XenforoResourceManagerAPI/blob/284b2888445a46263abcb40668a4804867203e96/support/Database.php#L56-L63

InventivetalentDev commented 4 years ago

Though, I've also stumbled upon a couple users that are returned by the API which have an empty identities array (instead of an object)
e.g.

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=68433
https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=68413
frostalf commented 4 years ago

if matters, while that api action returns 404, if you use action=getResourcesByAuthor&id=45870 it shows their resources.

jacobsandersen commented 4 years ago

I'll do some investigation on this ASAP.

Though, I've also stumbled upon a couple users that are returned by the API which have an empty identities array (instead of an object) e.g.

https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=68433
https://api.spigotmc.org/simple/0.1/index.php?action=getAuthor&id=68413

Good catch on the object vs array. That was unintentional. I'll make that more consistent.

jacobsandersen commented 4 years ago

So, on my local install of XenForo every new user has the xf_user_field_value's automatically generated although they are blank.

I am guessing Spigot's installation is not doing this, for whatever reason.

I am not sure if a different type of join would work better or if I should just do two separate queries for the necessary data.

Comments?

md-5 commented 4 years ago

@simpleauthority yeah I just picked a random user (45870) and xf_user_field_value is indeed empty for them

InventivetalentDev commented 4 years ago

Doing a left instead of an inner join should, in theory, help with this. Instead of not returning the users without identities at all, they should return NULL identities when left-joining.

jacobsandersen commented 4 years ago

Well, it's worth a try for sure. I'm not sure I understand why for some users it works but for others it doesn't when xf_user_field_value is always present but empty. The join should work in any case. I can't reproduce locally, so the way we'd have to test would be push to prod and see if it helped which is less than ideal.

md-5 commented 4 years ago

Could just wipe em from your test db. I'm not sure why they're not filled in on Spigot; could be xenforo versions or way users are created

jacobsandersen commented 4 years ago

Could just wipe em from your test db. I'm not sure why they're not filled in on Spigot; could be xenforo versions or way users are created

That's the thing though. On my test db, I have a user with blank xf_user_field_value's like you described (none are null) and it works fine. Since they're not null, the inner join should work just fine.

I'm open to trying the left join, but I can't reproduce locally so I would have no way of knowing if the change of join works or not.

md-5 commented 4 years ago

I'm open to trying the left join, but I can't reproduce locally so I would have no way of knowing if the change of join works or not.

DELETE FROM xf_user_field_value WHERE user_id=99

Its a test DB, you should just be able to do that and see if it still works

jacobsandersen commented 4 years ago

I gotcha. I'll try it soon.

Olzie-12 commented 4 years ago

This is weird, any updates on the solution?

jacobsandersen commented 4 years ago

I just regained access to an XF installation, so I'll be debugging this soon.

Olzie-12 commented 4 years ago

I just regained access to an XF installation, so I'll be debugging this soon.

Alright sounds good

jacobsandersen commented 4 years ago

Works fine locally with missing rows in the xf_user_field_value table -- in my local install, they're never missing, but they are in Spigot. This may be a patch fix from XF that I have which Spigot doesn't...unknown. Regardless, #29 fixes it.