The resource type repository provides the JSON API path prefix. When we set the default request _format, we are not using this value.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | interdiff.txt | 446 bytes | wim leers |
| #21 | 2971745-21.patch | 10.9 KB | wim leers |
| #15 | 2971745-15.patch | 10.9 KB | wim leers |
| #13 | 2971745-13.patch | 2.86 KB | wim leers |
| #13 | interdiff.txt | 2.67 KB | wim leers |
Comments
Comment #2
gabesulliceComment #3
gabesulliceComment #4
wim leersNice catch! This will make sites using
jsonapi_extrasto customize the prefix behave correctly. IOW: today, those sites behave incorrectly.I think we should postpone this on #2949632: Make ResourceTypeRepository aware of the path prefix.
Comment #5
wim leersComment #6
gabesulliceA few commits just landed. Re-rolling while it's fresh on my mind.
Comment #7
wim leers👍 Very thoughtful!
Comment #8
wim leersOops.
Comment #9
wim leersThis prediction came true: #2969398: When using JSON API Extras' ability to change the base path, 4xx errors returned for using an invalid field in filter or sort returns HTML response rather than JSON.
This is still blocked on #2949632: Make ResourceTypeRepository aware of the path prefix, which has been assigned to @e0ipso for a few weeks now, because it needs a coordinated release of
jsonapi_extras.Comment #10
wim leers#2949632: Make ResourceTypeRepository aware of the path prefix landed!
Comment #11
wim leersPatch still applies cleanly. Retesting…
Comment #13
wim leers#6 was against HEAD, #2949632: Make ResourceTypeRepository aware of the path prefix renamed that method. Of course that couldn't work.
Comment #14
wim leersI wanted to RTBC and commit this patch. But actually, having updated this patch, I realized something:
This is making a middleware dependent on another service.
That other service needs a boatload of entity services to be constructed, which is expensive. And because this middleware runs before the page cache middleware, that means every single page cache hit is going to be made slower by this. All of that, just for JSON API. So I tested the before/after of this patch (using
ab -c 1 -n 100 http://d8/foobar— i.e. a trivial 404 page that does not at all involve JSON API):"Only" 1 millisecond difference, but that's 20% slower, and only ~80% of the number of requests per second. That's a pretty big difference.
Normally, I would not care. But we're trying to move this into Drupal core. And the intent is for new Drupal UIs to be built atop JSON API. We can't have all of them be slowed down by this.
Comment #15
wim leersIf we'd implement this using a container parameter, then this performance problem would go away: no more services to construct.
And we're now at a unique time and place: #2949632: Make ResourceTypeRepository aware of the path prefix already means
jsonapi_extraswill need to be updated (it hasn't been updated yet). JSON API Extras can still make this customizable, but it will have to do this through a container service modifier, for example how\Drupal\language\LanguageServiceProvider::alter()sets thelanguage.default_valuescontainer parameter.Theoretically this is out of scope for this issue; but it's the necessary change (necessary for correctness) that this issue's patch was making that was causing the performance problem. Hence it's IMHO in scope.
So here's a completely alternative patch.
Comment #16
wim leersUnfortunately, @e0ipso tagged a release of JSON API before this was resolved, which led to a JSON API Extras bug report: #2982133: No longer works with JSON API >=1.21 (so either 1.21 or 1.22).
So this:
is no longer true.
I assigned #2982133 in the
jsonapi_extrasqueue to myself.Comment #17
wim leersPatch posted for
jsonapi_extrasat #2982133-4: No longer works with JSON API >=1.21 (so either 1.21 or 1.22).Comment #19
gerzenstl commentedI wasn't able to apply 2971745-15.patch. I realized that several commits have been added to 8.x-1.x branch since this patch was submitted.
We need to update the patch.
Comment #20
e0ipso👏🏽 Yay! Thanks for that @Wim Leers!
The tag was intentional despite the bug introduced in extras. I was hoping to get to the bug sooner, but I couldn't. Evil me thinks that if stuff is not broken ever you don't get contributions. We can see it as a way to attract new blood 😅
In general I like the approach of the patch. The only think I'm hesitant to sign-off on is the removal of the public method. Despite the white lie of making everything @internal I believe that other modules will need the base path information. In particular (at least) Open API will need it. Although you can still get the parameter directly from the container, so I don't feel strongly about it if you want to remove the method. It will add an additional break to JSON API Extras and Open API, but that may be OK according to the reasoning above.
Comment #21
wim leersRebased #15. Not sure what went wrong there.
Comment #22
wim leers:D No problem. But it left the JSON API module in the awkward place of trying to not break JSON API Extras, and being blocked on your feedback, and then you tagged a release and hence breaking it anyway! We were trying to do The Right Thing :)
My concern with doing that is mostly that it's not clear what the impact of that method is: is that the source of truth, or the container parameter? I'd rather avoid any ambiguity there if possible.
I'd be okay with retaining it to make things easier for JSON API Extras/Open API. But … Open API actually won't be affected, because it's ready JSON API Extras' settings directly:
And JSON API Extras is already broken by #2949632-34: Make ResourceTypeRepository aware of the path prefix having shipped in the 1.21 release of JSON API that you tagged a few days ago. So changing it again won't actually impact JSON API Extras!
Comment #23
wim leersRetitling and bumping priority per #14+#15+#20.
RTBC'ing per #20.
Comment #24
wim leers