Commit Graph

84 Commits

Author SHA1 Message Date
Leo Franchi 0fe3da55e3 Reduce number of queries done by bulk_add_subscriptions
We now bulk-fetch subscription information once from the database
and use it throughout bulk_add_subscriptions in order to avoid
hitting the db O(streams) times.

On my machine this shaved the accounts_register API call from making
66 queries to making 37 queries.

(imported from commit 5dd5ad3f50b2a6edf85b5f1d55ebd697a1c60647)
2013-09-27 10:26:11 -04:00
Leo Franchi 1e6b83b6c8 Fetch stream.realm information when fetching default streams
(imported from commit 08eb32e6ecda75b17d6532b0421c371de2327027)
2013-09-27 10:25:23 -04:00
Steve Howell 93347be4af Send less presence info to Tornado in do_send_messages().
When we send a message, we send some presence information to Tornado
to help it figure out how to generate emails for idle recipients of
a message.  This change limits the presence info to being the
intersection of present users and recipients of the message.  It is
just an internal optimization to avoid queueing up unneeded data.

The history behind this feature is that I implemented it a while
back, but I think I made a rebase mistake that sent all the presence
data over the wire, despite having code to filter on recipients.
It was mostly harmless, just leading to some inefficiency which is
now fixed.

(imported from commit 7c8e97705afb299c67b99053909e952fbc823551)
2013-09-25 14:50:40 -04:00
Zev Benjamin 90ee96d456 Split out presence and activity interval events from user_activity queue
(imported from commit 3c22448491867a9e72659629d5d0faaf12b85b2c)
2013-09-24 20:44:15 -04:00
Jessica McKellar f058e9cac5 Add backend support for newer realms receiving stream notifications by default.
(imported from commit ea8ee65071423a94a462571aa30013969d9f3f7a)
2013-09-24 16:19:53 -04:00
Steve Howell 50641c3337 [perf] Reduce the number of DB queries in send_message.
For a 4-person stream, we were hitting the DB 8 times, and 4 of
those queries were to lazily get user.email for the 4 recipients
due to upstream code using only().  I added user_profile__email
to the only() call.

I believe this regression started 9/18, and after pushing this
to prod, we would should look at this graph:

https://stats1.zulip.net/graphs/8274cd84588

(imported from commit 70629cb69fe5955c674ba76482609dfe78e5faaf)
2013-09-24 16:19:52 -04:00
Waseem Daher 7afd3ecc81 Custom invite text for MIT invitations.
(imported from commit 21b72861e991159eb7faa74809edb8d01027c6c8)
2013-09-20 12:06:26 -04:00
Steve Howell 6eda9c3314 Rename function to send_pm_if_empty_stream().
This used to have a really long name.

(imported from commit d3027a75f49db428239d432cfaa8821aa733eb04)
2013-09-20 10:19:07 -04:00
Steve Howell a457135a25 Use efficient stream.num_subscribers() for bot PMs.
Use stream.num_subscribers() in check_if_a_bot_is_sending_a_message_to_an_empty_stream().

The num_subscribers() function using Django's count() method, which returns
a single row, vs. len() on an iterator of query rows.

(imported from commit 6157fe248945e9288ee71d8cc39fb6dda4e9a247)
2013-09-20 10:19:07 -04:00
Steve Howell 5ae5e3f881 Disable empty-stream PMs for MIT bots.
(imported from commit a855d612b6ba316fc183200c4f72102831b6179c)
2013-09-20 10:19:07 -04:00
Steve Howell 098720b6d1 Extract check_if_a_bot_is_sending_a_message_to_an_empty_stream().
(imported from commit 3312d70f6b94f4a13a42bbe0320f4bb1062262e7)
2013-09-20 10:19:07 -04:00
Waseem Daher 190390d8ea Allow MIT to invite coworkers.
(imported from commit 273b3abdd3dcc49c01c1a04001450983d4acb000)
2013-09-19 17:14:41 -04:00
Kevin Mehall 6695105bb9 Fix 2499d7b to not break user registration.
Some bots created by us do not have owners. Don't try to send a
message to the nonexistent owner.

(imported from commit ab952eccd7d6c4728e9477a106142214b5c81ca9)
2013-09-19 13:42:20 -04:00
Jessica McKellar 7e733a1b91 Don't rate-limit missed message e-mails.
Instead just rely on the 2-minute delay in the management command to
batch conversations.

We've had people report being confused or thinking the feature was
broken when they didn't get e-mails because of our rate-limiting, so
let's see if this is not too overwhelming.

(imported from commit 706ddb07b906b5c2edea1159c04acc2ee6f06e29)
2013-09-19 11:55:42 -04:00
Steve Howell de0d50d31a [important] Fix recent regression w/maybe_get_subscribers
(imported from commit 8069f729dcb2bfec1c1df8f50a88fe49545a9a87)
2013-09-19 09:37:39 -04:00
Steve Howell 3c69a6dd26 Bulk-send peer_add events in bulk_add_subscriptions().
Send a single peer_add event per stream that has multiple users.

(imported from commit 1027b212557f848d437128a03698ecd54575c3fd)
2013-09-19 08:52:54 -04:00
Steve Howell c8c64984d3 Eliminate redundant peer_add notifications.
Don't send peer_add notifications to users who are already
getting add notifications, because they will already know
about subscribers.

(imported from commit 726b54ae0e30b71440b17d9c51b026872ea96218)
2013-09-19 08:52:54 -04:00
Steve Howell c58d366178 Optimize notifications from do_add_subscription().
Instead of sending one notification per user, bulk them up with
the users parameter.

(imported from commit c296f23599a214a63ef6f09406a9deaea469a7f3)
2013-09-19 08:52:54 -04:00
Steve Howell 8182d60961 Optimize query used by do_add_subscription().
It only grabs the user_profile_id column now.  This leads to a
speedup of about 16x between grabbing large ORM objects vs.
small 1-column dictionaries.

(imported from commit 95150bff3fdcbe250b04f014062224af42a6644f)
2013-09-19 08:52:54 -04:00
Steve Howell e89c6f64bd Extract notify_peers().
Splitting out notify_peers() will give us flexibility for cleaning
up how we notify peers for bulk adds.

(imported from commit e108fa2c432cc1fe54d788c58c82c983e0f2394e)
2013-09-19 08:52:54 -04:00
Steve Howell d24d8e4b36 Optimize showing subscribers on the settings page.
If you expand subscribers on your settings page, you will now see
a query like this in your postgres logs:

SELECT "zerver_userprofile"."email"
FROM "zerver_subscription" INNER JOIN "zerver_recipient" ON ("zerver_subscription"."recipient_id" = "zerver_recipient"."id") INNER JOIN "zerver_userprofile" ON ("zerver_subscription"."user_profile_id" = "zerver_userprofile"."id") WHERE ("zerver_recipient"."type" = 2  AND "zerver_subscription"."active" = true  AND "zerver_recipient"."type_id" = 40  AND "zerver_userprofile"."is_active" = true )

The join's still complicated, but the list of fields is one instead of 40+.

(imported from commit 48de1f888193a4d23fcea52d0b633d134e4a3ff7)
2013-09-19 08:52:53 -04:00
Steve Howell 9cdedf7e6c Optimize adding subscriptions with maybe_get_subscriber_emails().
To get emails, query one field instead of 40-ish fields.

(imported from commit d2dbbe23871df76bc7d431dcd9b19ebd7a58c161)
2013-09-19 08:52:53 -04:00
Steve Howell 986dd8289e Optimize get_subscribers back end.
get_subscribers_backend() now calls the new get_subscriber_emails()
function, which just queries the email field:

  "zerver_userprofile"."email"

...instead of querying about 40 fields that it never uses.

I was able to verify the query slimming by watching my postgres server log.

Also, you can verify that the ORM does roughly 16x less work using values():

>>> def f(): return [sub.user_profile.email for sub in list(Subscription.objects.all().select_related())]
...
>>> def g(): return [row['user_profile__email'] for row in list(Subscription.objects.all().values('user_profile__email'))]
...
>>> def timeit(func): t = time.time(); func(); return time.time() - t
...
>>> timeit(f)
0.045198917388916016
>>> timeit(g)
0.002752065658569336

(imported from commit a69f690a96d076b323fdfc2f4821b0548bdfac7f)
2013-09-19 08:52:53 -04:00
Steve Howell db2c9ff8c2 Extract get_subscribers_query
(imported from commit fea253591093a1f0cf722c1d4bcfb0df4f881984)
2013-09-19 08:52:53 -04:00
Leo Franchi d88266b41d Warn bot owners when a bot sends a message to a nonexistent stream
(imported from commit 2499d7bd9d176a7ab43f751eb855813d0a479bd4)
2013-09-18 15:54:13 -04:00
Leo Franchi 5441e36167 Bulk update messages in deprecated cache when updating message
(imported from commit 5e68e4eec83c0ed02b9997b0cb3f93ce8f0a7fdd)
2013-09-18 13:27:58 -04:00
Leo Franchi c588c7938c Allow message topic changing to propagate backwards
(imported from commit 470178ef5f7aaf09d4528c88ae6e33f17538fcaf)
2013-09-18 13:27:58 -04:00
Steve Howell 30b6f54a36 Don't cache UserPresence info.
(imported from commit ff590bdf5d84bb9b3cedc561c2f2fbf7f7592a66)
2013-09-17 14:51:56 -04:00
Jessica McKellar cfeaa2be9b Add backend support for realm admins to rename streams.
(imported from commit eaf419f1f68dfd350b8c99e8a5089ec316f0c409)
2013-09-16 16:16:13 -04:00
Steve Howell 1836d8958e Add comment about sending presence updates
(imported from commit da9c521a6ad652e4dbcaabcc3a24b3e23376f545)
2013-09-16 11:29:13 -04:00
Steve Howell 85f9b6695f Optimize user presence/activity query.
The get_status_dict_by_realm helper gets called whenever our
 realm user_presences cache expires, and it used to query these fields:

    "zerver_userpresence"."id", "zerver_userpresence"."user_profile_id", "zerver_userpresence"."client_id", "zerver_userpresence"."timestamp", "zerver_userpresence"."status", "zerver_userprofile"."id", "zerver_userprofile"."password", "zerver_userprofile"."last_login", "zerver_userprofile"."is_superuser", "zerver_userprofile"."email", "zerver_userprofile"."is_staff", "zerver_userprofile"."is_active", "zerver_userprofile"."is_bot", "zerver_userprofile"."date_joined", "zerver_userprofile"."bot_owner_id", "zerver_userprofile"."full_name", "zerver_userprofile"."short_name", "zerver_userprofile"."pointer", "zerver_userprofile"."last_pointer_updater", "zerver_userprofile"."realm_id", "zerver_userprofile"."api_key", "zerver_userprofile"."enable_desktop_notifications", "zerver_userprofile"."enable_sounds", "zerver_userprofile"."enter_sends", "zerver_userprofile"."enable_offline_email_notifications", "zerver_userprofile"."last_reminder", "zerver_userprofile"."rate_limits", "zerver_userprofile"."avatar_source", "zerver_userprofile"."tutorial_status", "zerver_userprofile"."onboarding_steps", "zerver_userprofile"."invites_granted", "zerver_userprofile"."invites_used", "zerver_userprofile"."alert_words", "zerver_userprofile"."muted_topics", "zerver_client"."id", "zerver_client"."name"

Now it queries just the fields it needs:

  "zerver_client"."name", "zerver_userpresence"."status", "zerver_userpresence"."timestamp", "zerver_userprofile"."email" FROM "zerver_userpresence"

Also, get_status_dict_by_realm is now namespaced under UserPresence as a static method.

(imported from commit be1266844b6bd28b6c615594796713c026a850a1)
2013-09-16 11:29:10 -04:00
Steve Howell e881fdd2ff Change the cache timeout for get_status_dict() back to a minute.
This function gets user presence information, which changes rapidly
and requires a pretty simple query.

(imported from commit f9b9f0f22277335c76eb4371930a4fff2758a240)
2013-09-16 11:24:29 -04:00
Steve Howell 99dd2ed8df Add presences info to the event data for process_new_message().
The do_send_messages() populates the user_presences data structure
for process_new_message(), so that Tornado code never needs to hit
the database or memcached to get the user presence info.

(imported from commit 194aeaead8fa712297a2ee8aff5aa773b92f1207)
2013-09-16 11:24:12 -04:00
Leo Franchi 6e56342cf6 Send missedmessage notifications if user is idle for >1hr
(imported from commit 573f46a77497cb2f73eae3b4a648e466977e6247)
2013-09-13 17:33:34 -04:00
Steve Howell b7ef86bc34 Added /json/set_muted_topics
(imported from commit e9072cd273fabf0e072b6a5e9ed80b07142f1013)
2013-09-11 16:47:37 -04:00
Leo Franchi a408192f92 Don't re-parse alert words more than necessary
(imported from commit 4fee6ad9592c1dc5f844889fcb6586192de6cb35)
2013-09-11 12:00:37 -04:00
Leo Franchi 9ebb536c2d Use json_to_bool in REQ instead of manually using ujson.loads
(imported from commit 5a607f7aba4a8e4e5920a35df06c375cff98ff55)
2013-09-10 13:25:59 -04:00
Tim Abbott 9fcca3df4e [schema] Collect data on when users are active on site.
These engagement data will be useful both for making pretty graphs of
how addicted our users are as well as for allowing us to check whether
a new deployment is actually using the product or not.

This measures "number of minutes during which each user had checked
the app within the previous 15 minutes".  It should correctly not
count server-initiated reloads.

It's possible that we should use something less aggressive than
mousemove; I'm a little torn on that because you really can check the
app for new messages without doing anything active.

This is somewhat tested but there are a few outstanding issues:

* Mobile apps don't report these data.  It should be as easy as having
  them send in update_active_status queries with new_user_input=true.

* The semantics of this should be better documented (e.g. the
  management script should print out the spec above)x.

(imported from commit ec8b2dc96b180e1951df00490707ae916887178e)
2013-09-10 13:25:59 -04:00
Scott Feeney b8dc9cc198 Send you the subscribers list when you add a subscription
(imported from commit 810de1f03c6765ef1c5476df30aff4c467783cab)
2013-09-06 23:13:47 -04:00
Scott Feeney f9cfa6b5f7 Include subscriber list in page_params.stream_list
(imported from commit 7f03eec37c7cbdcdefb590c39a76444bd1b55230)
2013-09-06 23:13:47 -04:00
Scott Feeney c46007e08e When a user subscribes to a stream, notify other stream subscribers
This is a backend-only change. No frontend code that uses this is
included.

(imported from commit 4bc379de3bbfc0975ff939fa5895d716a4d1ff1b)
2013-09-06 23:13:47 -04:00
Scott Feeney 65ed20469e Split out get_subscribers method on backend
(imported from commit b5941ff90bbf5b31a9fa31aa83e5d1856d483dcc)
2013-09-06 23:13:47 -04:00
Leo Franchi cf59f07fed Replace alert_words as event contains full list
(imported from commit 489975f8bcbd0c3bcec07dd5ed62de5cae686140)
2013-09-06 16:05:08 -04:00
acrefoot 592e1ead6b Actually use the realm specified by the email mirror when doing the markdown
(imported from commit 00b909b1d0c70a3523ab53d2f91815ab14ba2a6f)
2013-09-05 18:24:55 -04:00
Leo Franchi b2ddd670e4 [schema] Add backend support for per-user alert words
(imported from commit 7a9c596a010cbedbddf594c5d9c68bb9ed46d122)
2013-09-05 10:18:40 -04:00
Kevin Mehall 19a835e7d5 Add a checkbox that propagates topic edits to subsequent messages.
Trac #1348

(imported from commit 28e2a8cb3ecda5ec50d17501f4ccbd8644212065)
2013-09-04 14:51:46 -04:00
Leo Franchi 7e6af0a5d0 Mark messages from the desktop app as sent_by_human
(imported from commit 001073221387cbbaa541b17f9a377490562a28f1)
2013-09-04 11:00:11 -04:00
Tim Abbott eeb04ed78e deactivate_user: Only delete sessions that aren't expired.
(imported from commit e3d844a55581a7e7faab8ea9ed6703480fae8f51)
2013-09-03 11:40:42 -04:00
Scott Feeney e3247de572 Factor out get_active_user_profiles_by_realm()
(imported from commit 634ebf265b02303a938f7595de3622e25bc22b49)
2013-08-29 10:28:20 -04:00
Tim Abbott ac1f9b5128 check_message: Allow zephyr mirroring bot to send to invite-only streams.
(imported from commit d45c75915cc4e29328768f1ed0e0ec972e5b7269)
2013-08-28 19:07:05 -04:00