RyanBalfanz / django-sendgrid

SendGrid for Django
http://pypi.python.org/pypi/django-sendgrid
97 stars 26 forks source link

sendgrid.views.listener uses a full index scan #59

Open RyanBalfanz opened 11 years ago

RyanBalfanz commented 11 years ago

Questionable Query:

SELECT `sendgrid_event`.`id`, `sendgrid_event`.`email_message_id`, `sendgrid_event`.`email`, `sendgrid_event`.`event_type_id`, `sendgrid_event`.`creation_time`, `sendgrid_event`.`last_modified_time`, `sendgrid_event`.`timestamp` FROM `sendgrid_event` ORDER BY `sendgrid_event`.`id` DESC LIMIT ? FOR UPDATE

Stack Trace:

File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/gevent/greenlet.py", line 390, in run
    result = self._run(*self.args, **self.kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 45, in handle
    self.handle_request(listener, req, client, addr)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 119, in handle_request
    super(GeventWorker, self).handle_request(*args)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 93, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/web_transaction.py", line 780, in __call__
    result = application(environ, _start_response)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/object_wrapper.py", line 220, in __call__
    self._nr_instance, args, kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/function_trace.py", line 93, in literal_wrapper
    return wrapped(*args, **kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/web_transaction.py", line 669, in __call__
    return self._nr_next_object(environ, start_response)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
    response = self.get_response(request)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/object_wrapper.py", line 220, in __call__
    self._nr_instance, args, kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/hooks/framework_django.py", line 475, in wrapper
    return wrapped(*args, **kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/views.py", line 395, in listener
    response = handle_batched_events_request(request)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/views.py", line 356, in handle_batched_events_request
    batch_create_events(events)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/transaction.py", line 223, in inner
    return func(*args, **kwargs)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/views.py", line 252, in batch_create_events
    batch_create_events_with_message_ids(eventsWithMessageIds)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/views.py", line 238, in batch_create_events_with_message_ids
    Event.objects.bulk_create_with_manual_ids_retry([tup[0] for tup in eventTuplesWithoutEmails] + eventsWithEmails)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/mixins.py", line 40, in bulk_create_with_manual_ids_retry
    return self.bulk_create_with_manual_ids(instances)
File "/var/www/MindSnacks-API/.venv/src/django-sendgrid/sendgrid/mixins.py", line 30, in bulk_create_with_manual_ids
    start = self.select_for_update().all().order_by('-pk')[0].pk + 1
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 215, in __getitem__
    return list(qs)[0]
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 92, in __len__
    self._result_cache.extend(self._iter)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 344, in _safe_iterator
    for item in iterator:
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 301, in iterator
    for row in compiler.results_iter():
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
    for rows in self.execute_sql(MULTI):
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
    cursor.execute(sql, params)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 120, in execute
    return self.cursor.execute(query, args)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/hooks/database_dbapi2.py", line 36, in execute
    return self._nr_cursor.execute(sql, *args, **kwargs)
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/time_trace.py", line 82, in __exit__
    self.finalize_data()
File "/var/www/MindSnacks-API/.venv/local/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/database_trace.py", line 55, in finalize_data
    traceback.format_stack())
RyanBalfanz commented 11 years ago

/cc @hoddez