Are these calls from your own template/client? If the records are not
critical, ie. for billing, throttling, have you considered just firing a
second js request to the background *in the client* to record the event
after the first ajax request is processed. Or if there are a lot of
requests per session you could batch them together occasionally like 10 or
20 events to 1 analytic request. Without batching that would double the
amount of requests you would have to process though, but maybe would be
simpler than other solutions if the event accuracy is not critical. Just
throwing that out there.
On Saturday, November 10, 2018 at 2:25:36 PM UTC-8, Zsolt Ero wrote:
>
> On a fairly classic Pyramid app (sync, gunicorn, SQLAlchemy / Postgresql,
> like the starter template), I am storing analytics-like events in a table
> for some of my views.
>
> Like this skeleton:
>
> @view_config(route_name='test', request_method='POST', renderer='json')
> def test(request):
> # body of the view
> map_id = request.json_body.get('map_id')
> data = {...}
>
> event_data = {'action': 'viewed'}
> event = MapEvent(user=request.user, action=event_data, map_id=map_id)
> request.dbsession.add(event)
>
> return data
>
>
>
> My problem is that while 99% of the views make read-only requests to the
> database, and thus are very fast, the analytics event is a writing and can
> be slow occasionally.
>
> Would it be possible to somehow send the request to the client and still
> keep processing the view? Like a send() + end() method or something
> similar, without returning?
>
> // Adding to a tasks queue is not an option as it'd be an overkill and an
> overcomplicated solution, which wouldn't work for hundreds of thousands of
> events per day.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/33f09955-5300-4964-9bea-96884096780e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.