zulip/zerver
Steve Howell c19b3aec0c Avoid sorting in UserPresence query.
We were using `.order_by('user_profile_id', '-timestamp') in our
UserPresence query in get_status_dicts_for_query.

We don't need a full sort to produce the dictionary of statuses.
In fact the whole operation in Python is still O(N):

    - divvy rows up to be per-user in an O(N) pass
    - find max row for the 'aggregated' entry in an O(n) pass
      per user

The one minor annoyance of this fix is that datetime_to_timestamp
is lossy, so if you naively call to_presence_dict before finding
the "max" row, you get test flakes if rows are created during the
same second.  I decided to avoid calling to_presence_dict so there
are fewer moving parts, but there's still the ugly step of having
to remove the "dt" field from the final results.
2017-09-08 12:32:17 -07:00
..
fixtures test fixtures: Add some more quotes and remove some Oscar Wilde. 2017-08-23 13:00:39 -07:00
lib fix_unreads: Add docstring explaining migration use case. 2017-09-07 07:06:03 -07:00
management fix_unreads: Remove commit() call in fix(). 2017-09-07 07:06:03 -07:00
migrations Add migration to fix unread messages. 2017-09-07 07:06:03 -07:00
templatetags templatetags: Fix buggy exception clause. 2017-08-25 00:39:58 -07:00
tests fix_unreads: Remove commit() call in fix(). 2017-09-07 07:06:03 -07:00
tornado Calculate idle users more efficiently when sending messages. 2017-09-07 06:59:44 -07:00
views Add MutedTopic model. 2017-09-02 09:19:51 -07:00
webhooks trello: Use client_head wrapper in tests. 2017-08-26 13:45:27 -07:00
worker mypy: Set assign_queue() parameter queue_type to not be Optional. 2017-08-07 21:27:50 -07:00
__init__.py
apps.py Add notifications on new logins to Zulip. 2017-03-25 16:50:52 -07:00
context_processors.py settings: Rename SERVER_URI to ROOT_DOMAIN_URI. 2017-08-28 14:09:28 -07:00
decorator.py logger: Add new create_logger abstraction to simplify logging. 2017-08-27 18:31:53 -07:00
filters.py mypy: Added Dict, List and Set imports. 2017-03-04 14:33:44 -08:00
forms.py forms: Replace is_inactive with more comprehensive check. 2017-08-24 23:16:31 -07:00
logging_handlers.py logging_handlers: Fix tracebacks being emailed in subject lines. 2017-04-25 18:55:11 -07:00
middleware.py mypy: Correct 2 type annotations in zerver/middleware.py. 2017-08-15 17:50:18 -07:00
models.py Avoid sorting in UserPresence query. 2017-09-08 12:32:17 -07:00
signals.py Update "MacOS" text to "macOS" 2017-08-26 09:00:42 -07:00
static_header.txt
storage.py mypy: Remove type: ignores not needed in Python 3. 2017-08-25 11:04:20 -07:00