Closed tremby closed 7 years ago
One thing I'm not totally happy with here is that this event is the only place the JSON returned from the API is made available.
I did that because my use case is profiling the queries, and without returning this JSON I can't log the number of documents returned by the query. The only way I could do that without providing the JSON (or just providing certain parts of it, like the counts of results and total results) would be to emit this event later, once the result set has been parsed to a Results
object. But this will make the timing less accurate, and it also wouldn't ever emit for ->count()
queries, where the result set is not actually parsed to a Results
.
Any thoughts?
Is it okay as it is, or should I return just results_size
and total_results_size
along with it?
Anyone taken a look at this yet?
Hi Bart,
I'm not sure we want to include that, we're trying to keep the kits as simple as possible. What's the problem you're trying to solve exactly?
Currently I'm using it to log and profile queries to the Prismic API. It is helping weed out duplicate queries and find things which can be optimized.
You're already listing the Symfony Event Dispatcher package as a dependency; may as well use it... ;)
Anything I can do to get this included? Any way I can simplify it? Want me to write some documentation? Tests are included, as you can see.
Any reason? You don't think it's useful?
Sorry @tremby. I should leave a comment after closing. I think we don't really need this at the moment. If more users ask for it, we could add it further.
A new method
Api#getDispatcher
is added, which gets anEventDispatcher
instance. Events can be subscribed to/listened for via this object.The events
prismic.pre_submit
andprismic.post_submit
are fired just before a search form is submitted and just after the response is received and parsed as JSON, respectively. Both events allow theSearchForm
object to be retrieved, inspected and operated on, and theprismic.post_submit
event additionally provides the JSON response object and a boolean denoting whether the response came from the cache or not.Using these events, a developer can for instance alter the form before it is sent, or log queries and how long they take.