You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The methods input() and body() are called from different places in the request class. One such place being get(). If a controller wants to update or create a model like in the following code ...
... then the whole data from the request will get parsed, evaluated and sanitized 3 times. It would be better if the data would only be parsed once and only upon usage. Something like the following code might achieve this:
class Request {
...
// Keep a cached version of the result of input()
protected static $input = null;
...
public static function input(bool $safeData = true)
{
// Check if input was calculated before, if yes, return it immediately
if (static::$input) return static::$input;
// Handling for first-time processing
$handler = fopen('php://input', 'r');
$data = stream_get_contents($handler);
$contentType = Headers::get('Content-Type') ?? '';
...
// Cache data
static::$input = $safeData ? \Leaf\Anchor::sanitize($data) : $data;
// Return
return static::$input;
}
}
The text was updated successfully, but these errors were encountered:
@patrickvuarnoz that's correct, yes we can save a bit of performance by implementing a caching layer on the request, however, something like this won't work because of other systems like Swoole otherwise we risk having data crossing into subsequent requests.
We have plans for a caching layer all over Leaf, but there are a few more pressing things at the moment
The methods
input()
andbody()
are called from different places in therequest
class. One such place beingget()
. If a controller wants to update or create a model like in the following code ...... then the whole data from the request will get parsed, evaluated and sanitized 3 times. It would be better if the data would only be parsed once and only upon usage. Something like the following code might achieve this:
The text was updated successfully, but these errors were encountered: