Commit Graph

5681 Commits

Author SHA1 Message Date
Steve Howell 730da55bf8 Pre-fetch user ids for presence query.
Before this commit, postgres would choose a non-optimal query
plan to find all presence rows belonging to a realm.  We now
do an extra query to get the list of relevant user_ids, which allows
the next query to take advantage of UserPresence's index on
user_profile_id.

Here is the query plan for the offending query (this particular query isn't
verbatim from the code, but it's representative of the problem):

    explain analyze
    select client_id
    from zerver_userpresence
    INNER JOIN zerver_userprofile ON
        zerver_userprofile.id = zerver_userpresence.user_profile_id
    WHERE
        zerver_userprofile.is_active and
        zerver_userprofile.realm_id = 3;

     Hash Join  (cost=149.66..506.82 rows=5007 width=4) (actual time=48.834..121.215 rows=5007 loops=1)
       Hash Cond: (zerver_userprofile.id = zerver_userpresence.user_profile_id)
       ->  Seq Scan on zerver_userprofile  (cost=0.00..260.11 rows=5369 width=4) (actual time=0.009..24.322 rows=5021 loops=1)
             Filter: (is_active AND (realm_id = 3))
             Rows Removed by Filter: 3
       ->  Hash  (cost=87.07..87.07 rows=5007 width=8) (actual time=48.789..48.789 rows=5010 loops=1)
             Buckets: 1024  Batches: 1  Memory Usage: 196kB
             ->  Seq Scan on zerver_userpresence  (cost=0.00..87.07 rows=5007 width=8) (actual time=0.007..24.355 rows=5010 loops=1)
     Total runtime: 145.063 ms

You can see above that we're filtering on realm_id instead of using an index.

When you decompose the query into two queries, the total time is about 100ms, for a
savings of 33%.  I imagine the savings would be even greater on an instance with lots
of realms.  This was tested on dev with one really large realm and one tiny realm.
2017-09-08 12:32:17 -07:00
Steve Howell 6076a6a38d Remove unused is_mirror_dummy fields. 2017-09-08 12:32:17 -07:00
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
Steve Howell 642e059725 fix_unreads: Add docstring explaining migration use case. 2017-09-07 07:06:03 -07:00
Steve Howell 4dfe6bb320 Add migration to fix unread messages. 2017-09-07 07:06:03 -07:00
Steve Howell 69203c1c81 fix_unreads: Remove commit() call in fix().
The commit() call in fix() breaks migrations and tests (unless you
mock) due to outer transactions.

We now explicitly call commit() from the management command.
2017-09-07 07:06:03 -07:00
Steve Howell 638675cd7e fix_unreads: Use raw SQL to check topic mutes.
Using raw SQL for checking the topic mutes makes it easier
to use the library in a migration.
2017-09-07 07:06:03 -07:00
Steve Howell 8cc8e87daf fix_unreads: Use logging instead of print. 2017-09-07 07:06:03 -07:00
Steve Howell a2fe4178be Extract zerver/lib/fix_unreads.py.
This is a pure code move.
2017-09-07 07:06:03 -07:00
Steve Howell 848c0803bd Exclude muted topics from unread count. 2017-09-07 07:06:03 -07:00
Steve Howell f5edeb01ae Calculate idle users more efficiently when sending messages.
Usually a small minority of users are eligible to receive missed
message emails or mobile notifications.

We now filter users first before hitting UserPresence to find idle
users.  We also simply check for the existence of recent activity
rather than borrowing the more complicated data structures that we
use for the buddy list.
2017-09-07 06:59:44 -07:00
Steve Howell 97c5f085e7 minor: Extract locals in do_send_messages().
This is a prepartory commit for another refactoring.
2017-09-07 06:59:44 -07:00
Steve Howell 981f557422 Extract receiver_is_off_zulip().
We are splitting out this logic from the more complicated
UserPresence-related logic, so that we can simplify the latter.
2017-09-07 06:59:44 -07:00
Steve Howell 776bdc59db Avoid unnecessary steps in process_message_event().
There is no reason to compute receiver_is_idle() unless a user
is actually PM'ed or mentioned.
2017-09-07 06:59:44 -07:00
Umair Khan f7d8db792c makemessages: Allow whitespaces after comma in i18n.
We allow such patterns:

```
i18n.t('Test __variable__',
        {variable: "script"})
```
2017-09-06 07:01:43 -07:00
Steve Howell 0721115c64 model: Remove user_profile.muted_topics.
(We now track muted topics in the MutedTopic model.
2017-09-02 09:19:51 -07:00
Steve Howell 4ac6bc46c7 Add MutedTopic model.
This commit completely switches us over to using a
dedicated model called MutedTopic to track which topics
a user has muted.

This includes the necessary migrations to create the
table and populate it from legacy data in UserProfile.

A subsequent commit will actually remove the old field
in UserProfile.
2017-09-02 09:19:51 -07:00
Steve Howell 06ca364049 minor: Test round-trip behavior for mutes.
Instead of peeking directly at the DB to verify our mutes are
set correctly, we now use the library function.  This prepares
us to modify the DB internals while preserving the tests.
2017-08-30 09:14:41 -07:00
Brock Whittaker 2140a4aa01 landing: Add /plans/ describing ways to use Zulip.
Note from tabbott: This isn't yet linked to and will need to go
through significantly more iteration, but it's a start.
2017-08-30 07:56:22 -07:00
Greg Price a4bcf1a64b APNs: Handle HTTP connection errors, and retry.
Should help with #6321 as at least a band-aid.
2017-08-29 15:27:41 -07:00
Greg Price 780e1ac5b2 push notifs: Add a simple test for the new APNs provider. 2017-08-29 15:27:41 -07:00
Steve Howell 0501570cd1 Remove POST-based API for setting topic mutes. 2017-08-29 16:53:38 -04:00
Steve Howell 828459a24b Extract build_topic_mute_checker into topic_mutes.py.
We had two duplicate versions of this function, and one
of them was broken with respect to case insensitivity.
2017-08-29 16:53:38 -04:00
Steve Howell 8c4a5a9f7a Extract exclude_topic_mutes.
This is mostly a pure code move, but I cleaned up the code
slightly to use early-return.
2017-08-29 16:53:38 -04:00
Steve Howell 0959c978c3 Fix lint error from recent subdomains commit.
We did a code sweep recently for subdomains (see
60be89d0).
2017-08-29 08:35:37 -07:00
Tim Abbott 60be89d00e test_push_notifications: Declare subdomains explicitly. 2017-08-28 23:19:07 -07:00
Tim Abbott c5d699b6fb tests_classes: Add DEFAULT_SUBDOMAIN feature.
This should make life a little easier for those tests that need to use
the same subdomain like 20 times.
2017-08-28 23:17:33 -07:00
Tim Abbott 4a22316d90 test_decorator: Add explicit subdomains in tests. 2017-08-28 22:51:57 -07:00
Tim Abbott a8b9ffc020 test_classes: Include more detail in incorrect JSON responses.
If the status code is wrong, we show the actual error message now,
which often saves a bit of time when debugging.
2017-08-28 21:43:41 -07:00
Rishi Gupta c1997e759c password_reset: Change email to be appropriate for obtaining first password.
The situation if, for instance, the user signed up via google auth, and now
needs a password to get their API key.
2017-08-28 20:39:53 -07:00
Tim Abbott f1ad819547 home: Remove compatibility code for old name Humbug.
Since Zulip stopped being called Humbug in like 2013, this code hasn't
been useful in years, and is a bit confusing.
2017-08-28 16:15:58 -07:00
Steve Howell 0106add546 mypy: Use TypedDict for UnreadMessageResult. 2017-08-28 14:48:19 -07:00
Tim Abbott 50f5560bd1 accounts: Standardize URL for find_account.
This changes it to match the /accounts/ URL style for all of our other
auth code path endpoints.
2017-08-28 14:36:59 -07:00
Tim Abbott ac0d90e533 portico: Rename 'find_my_team' to 'find_account'. 2017-08-28 14:29:29 -07:00
Tim Abbott a0a1fe1512 settings: Rename SERVER_URI to ROOT_DOMAIN_URI.
This should be a lot less confusing.

See #6013 for discussion.
2017-08-28 14:09:28 -07:00
Yago González 659bff1ffb i18n: Fix URLs misparsing in translation tags.
The double forward slash (//) after the protocol in URLs was being
mistakenly considered the beginning of an inline JS comment, causing
internationalization strings being cut unexpectedly.

Now the check for inline JS comments is only run in .js files.
2017-08-28 13:54:17 -07:00
Umair Khan ecfafc05c0 registration: Use already_registered to show error.
Use this new variable to determine if the user already exists while
doing registration. While doing login through GitHub if we press
*Go back to login*, we pass email using email variable. As a result,
the login page starts showing the "User already exists error" if we
don't change the variable.
2017-08-28 07:02:11 -07:00
Steve Howell 73c30774cb admins: Add private streams to never_subscribed.
Admins need to know about private streams to delete them, even
if they are not subscribed.  We send the minimal info possible
to the client to allow them to have a UI for that.
2017-08-27 19:08:04 -07:00
Steve Howell 8ea9b80a8c Clean up test_never_subscribed_streams().
This basically extracts a few helper methods and makes the data
setup a bit more explicit.
2017-08-27 19:08:04 -07:00
Steve Howell 313f73258d Allow admins to delete private streams (backend only).
This is the backend piece.  Getting the UI right here is a bit
more complicated here, but this allows admins to use the API
to delete streams.
2017-08-27 19:08:04 -07:00
Aditya Bansal d9c9bfe7f6 logger: Add new create_logger abstraction to simplify logging.
This deduplicates a ton of Python logger-creation code to use a single
standard implementation, so we can avoid copy-paste problems.
2017-08-27 18:31:53 -07:00
Tim Abbott e092f1afff logging: Fix soft_deactivation log declaration.
Apparently, the soft deactivation log was incorrectly grabbing the
root logger, and thus screwing up where everything got logged.
2017-08-27 18:30:52 -07:00
Tim Abbott 70e16da81c decorator: Fix request.user handling of remote servers.
The refactor in b46af40bd3 didn't
correctly translate the code for managing request.user and
request._email, resulting in requests for the push notification
bouncer being rejected with this exception:

AttributeError: 'AnonymousUser' object has no attribute 'rate_limits'
2017-08-27 16:35:17 -07:00
Preston Hansen 5a501784f2 digest emails: Add unit tests for digest email management.
Fixes #6266.
2017-08-27 13:10:14 -07:00
Vishnu Ks 8fc8ac0799 management: Override CommandError to mention --entire-server argument. 2017-08-27 12:34:23 -07:00
Vishnu Ks dc63f838d7 backend-tests: Add tests for get_users with all-users argument enabled. 2017-08-27 12:34:23 -07:00
Vishnu Ks 23b63238c4 management: Handle the invalid user arguments cases separately. 2017-08-27 12:34:23 -07:00
Aditya Bansal b232563e12 soft-deactivation: Add cron job for weekly soft deactivating users. 2017-08-27 11:33:06 -07:00
Aditya Bansal 9d7e23c100 softdeactivation/management: Make specifying realm an optional arg. 2017-08-27 11:33:06 -07:00
Tim Abbott ed31a5988c models: fix badly line-wrapped type annotation.
Fixes #6290.
2017-08-27 11:27:07 -07:00