Commit Graph

301 Commits

Author SHA1 Message Date
Zev Benjamin 22e2eb3305 Use different mixpanel tokens while deployed vs in development
(imported from commit 4fac466a822d49cb0e1a7592dbd77d8ee019803e)
2013-05-21 17:56:49 -04:00
Zev Benjamin ae9be7298d Wrap render_to_response
(imported from commit d23aa3e5ad4c5243e83df098953ea4b1f7b3c294)
2013-05-21 17:56:49 -04:00
Tim Abbott d467a93877 Add support for updating messages after they've been received.
Currently the interface for editing messages is limited to a
command-line API tool; it's great for testing with e.g.:

./api/examples/edit-message --message=348135 --content="test $(date +%s)" --site=http://localhost:9991 --subject="test"

The next commit will add a user interface for actually doing the editing.

(imported from commit bdd408cec2946f31c2292e44f724f96ed5938791)
2013-05-20 23:40:26 -04:00
Tim Abbott 56949b4788 Create subscription objects in bulk by user_profile.
This, combined with acrefoot's work on sending the notifications in
bulk, resolves trac #1142 -- we do only 10 database queries and the
whole operation completes in about 300ms on my laptop.

(imported from commit 36b5bb836bc6c713903d1ca72e39af87775dc469)
2013-05-20 23:29:54 -04:00
Tim Abbott c325794f3c Send Markdown parser failures to the errors stream.
(imported from commit 8638744ec45d6505fe3a7be87df0a70943f23996)
2013-05-20 23:29:54 -04:00
Luke Faraone 1bb9def157 Only contact embed.ly if we have items that are not cached to fetch.
(imported from commit 8016d1f5dac6a75ced63bec8f0f11d9e4020cccb)
2013-05-14 08:00:37 -07:00
Tim Abbott a4c5c24029 Use the event system to sync onboarding steps across browser tabs.
(imported from commit 29311390133aca8f3a3d79fbe06dbbcabc4fb6ea)
2013-05-14 10:27:40 -04:00
Jessica McKellar 76a57e78ed Enumerate onboarding steps client-side, and give a way to update them.
(imported from commit 0a993976e898cdb20ebb814a19d520572ef8b7e6)
2013-05-14 10:27:39 -04:00
Jessica McKellar 24bb8ad797 onboarding: give new users a list of uncompleted onboarding steps.
(imported from commit 068a6e2112db98965ec5a1c5fc69a9fe285c0333)
2013-05-14 10:27:39 -04:00
Tim Abbott c6f04a2c75 Do memcached accounting on the memcached repopulating commands.
(imported from commit 56b30c04e7aee9c9d8493d872b3b367f2be14262)
2013-05-13 17:11:31 -04:00
Leo Franchi 7f04c8f9b9 Set a Reply-To header in our missed emails, and from noreply@
Otherwise, warn about not replying to this email.

(imported from commit bdcd8f510a8636b25c3c28aaef146a6e916a7d9f)
2013-05-13 11:59:35 -04:00
Leo Franchi 29413867b7 Use just one cache key for all tweet lookups
Since we log to statsd our cache time lookups by cache key, using a unique
tweet id for each lookup was just filling up our cache without being useful.

Also, log database cache lookups in a further namespace to distinguish between
memcached caches

(imported from commit a2a16b777fb7ab8cd066feee7344f9c8a3c107f5)
2013-05-11 15:51:40 -04:00
Zev Benjamin 5508fb5f91 Add restrictions on which streams you can send to
Users can send to any stream except invite-only streams that they
aren't subscribed to.  Bots can send to any stream except invite-only
streams that neither they nor their owner is subscribed to.

(imported from commit 623d34d249d923611ca7ca781b5b55205cd3e548)
2013-05-11 02:38:32 -04:00
Zev Benjamin 73be68fbb9 [schema] Add support for bot users
(imported from commit 634a8211b41fd0040c95b51b96a88d3517fa8cf4)
2013-05-11 02:38:32 -04:00
Tim Abbott 97840da0d2 Fix memcached accounting for bulk set/gets.
After this change, the memcached time consumed by doing
get_old_messages for 200 and 1000 messages respectively now look like
this:

200  63ms (mem: 6ms/3) (db: 4ms/2q) /json/get_old_messages
200 178ms (mem: 67ms/2) (db: 6ms/1q) /json/get_old_messages

which might help explain where the time is going on prod for some of
our slower queries.

(imported from commit b8fe83b175914b6796922a65a1c5537f4e7a9429)
2013-05-10 17:52:45 -04:00
Leo Franchi c28968c848 Only send huddles once per email
(imported from commit 5dc9e209346d14f3c5af1d07e626d771c7d3a95d)
2013-05-09 15:50:05 -04:00
Luke Faraone 3c08781764 Limit the number of URLs we parse at once to 5.
(imported from commit 876c0d0713b4a4d328e4a69e46c984694f5bce1b)
2013-05-09 10:44:08 -04:00
Luke Faraone 2c44ed1096 Log URLs that cause Embedly timeouts.
(imported from commit 84fdca163f6fefae5adc5ea4849d4d707aa7049e)
2013-05-09 10:44:08 -04:00
Luke Faraone f8d443c3c9 Time out embed.ly calls after 2.5 seconds.
(imported from commit 903b800a8444ff5c0b463dba17b2653e1775ae81)
2013-05-09 10:44:08 -04:00
Waseem Daher 47ac589f87 Make inline previews smaller.
(imported from commit 228f6f6f296877810824f98ea8001e47cf955cf1)
2013-05-09 10:44:08 -04:00
Luke Faraone 0513d9760a Batch-process and cache responses from the Embedly API
(imported from commit c427e2bf8f0f32dc632b05f41fa18ab10d0b6d03)
2013-05-09 10:44:08 -04:00
Luke Faraone 9fec3cd3c0 Explicitly skip Twitter links.
(imported from commit 2452dd4d92febbfc2b83ab0e09d7158f4bda76e3)
2013-05-09 10:44:08 -04:00
Luke Faraone fac83ed2b7 [manual] Add support for Embedly Extract
For sites that are supported, we now grab thumbnails for images + video
embed code for videos and use them in lieu of our existing embed code.

We also embed rich non-script content.

Special casing is done so that we don't embed images twice.

Some testcases were modified to avoid triggering Embed.ly

The manual step is to install python-embedly.

(imported from commit d725bab91675c61953116c5ca741055fce49724e)
2013-05-09 10:42:49 -04:00
Luke Faraone 8601c1670f bugdown: Factor out creating a link into its own method
(imported from commit 869cec9927570c4126b78f90aeedc2d5b542d097)
2013-05-09 10:42:19 -04:00
Luke Faraone 598c3a00f2 Comment change: link to a StackOverflow answer directly
(imported from commit a106b02e734956cab88445d159be18a092ae6d46)
2013-05-09 10:41:33 -04:00
Luke Faraone a470ec2e71 Pass the full stack trace in markdown processor errors.
(imported from commit fb157ab44fbf1465d1529ded4af4e04b2c7e9c55)
2013-05-09 10:41:32 -04:00
Tim Abbott 4ab4772758 Only register a Tornado rabbitmq handler if we're using rabbitmq.
(imported from commit 726934bc9acab3b19720f6b5ab1d0736ddd96832)
2013-05-09 10:35:49 -04:00
Leo Franchi 246b4a8459 Fix humbug url
(imported from commit b0fb11acd5f957a71387fe997d292fd6a9d17f39)
2013-05-09 10:35:48 -04:00
Leo Franchi 4173862833 Send notification with missed message to users if they received a PM while offline
This is configurable in the user's settings on Humbug

(imported from commit 80bf6d7a6f0dc3811117548e2225865db8b533d9)
2013-05-09 10:35:48 -04:00
Leo Franchi 06f33a2bde Add code to generate emails for messages that a user missed
(imported from commit 36d3dd9bebbdc9d2af0b0f14acd7f0f6550be4b4)
2013-05-09 10:35:48 -04:00
Leo Franchi 26fd7649f7 Add queue support for draining a queue completely
(imported from commit 50cc52f8b5b74b274024222596c6f2bd27832c89)
2013-05-09 10:35:48 -04:00
Tim Abbott 74148518b4 events: Fix the requesting client type being always internal.
(imported from commit b03bee006547ee811c2f0af66d82dfe6bc4331fc)
2013-05-09 10:35:47 -04:00
Tim Abbott d45527864c bugdown: Include server name in markdown failure emails.
(imported from commit 5b090480a66ca04f7b065215c8c5da698b6c5358)
2013-05-09 10:35:45 -04:00
Leo Franchi 0da2f51ddb Calculate presence information with delta between server timestamp
(imported from commit b4b367ed620878e6d01287cb1aaae0730c7475c8)
2013-05-06 13:52:23 -04:00
Tim Abbott f06fdbb7a8 Fix Zephyr mirroring loop detection with new events API.
(imported from commit 79454bb26851b2f4a61d6cdf04350386671618a5)
2013-05-03 18:20:34 -04:00
Luke Faraone 6bc2d21b87 Make audible notifications a tunable.
This decouples from Chrome notifications, which gives us cross-platform
support in at least modern browsers.

We log this action so its replayable in our message logs.

This implements the model change indicated by the previous schema commit.

(imported from commit b21213cdde54f43670bbb0bf1f607147fc732b38)
2013-05-03 15:08:49 -07:00
Jeff Arnold 105fdc076b Reserve height=100 for images so that collapsing takes them into account
Addresses #1204

(imported from commit 9a1f4b13ab14c4b8fc4eab50178b9c28f477fcd7)
2013-05-02 18:53:34 -04:00
Leo Franchi 5ef7c4e6db Add a management command for active user stats
(imported from commit a4227858b422c48e272700880e0c21889c7ce566)
2013-05-01 11:17:18 -04:00
Tim Abbott e3bb1bc8ec bugdown: Fix tweet ID extraction from twitter urls.
(imported from commit 88b9882527a5317bf30bcc5f0d1255e819ea149c)
2013-04-30 10:43:17 -04:00
Tim Abbott 7c001822f2 Use bulk requests for updating memcached in get_old_messages.
Otherwise we end up doing 1000 requests to memcached, which can be
quite expensive.

(imported from commit be247f63b5fb88c6f4a45326261b66ea67fe1028)
2013-04-25 14:43:37 -04:00
Zev Benjamin 3e1ec5d7c9 Increase size of initial message cache fetch and exclude tabbott/extra's messages
(imported from commit 59544aa3adfb05f50ca69e56f37f57944dfa0b81)
2013-04-25 13:33:51 -04:00
Zev Benjamin a1634b12d3 Increase efficiency of initial message cache query
In repeated trials, the initial data fetch used to take about 1100ms.
In practice, it was often taking >2000ms, probably due to caching
effects.  This commit cuts the time down to about 300ms in repeated
trials.

Note that the semantics are changed slightly in that we may no longer
get exactly 25000 messages.  However, holes in the message_id
sequence are currently very rare or non-existent so this shouldn't be
a problem and we don't care about the exact number of messages
anyway.

I believe the problem was that the query planner was unable to
effectively use the LIMIT clause to figure out that only a small
subset of zephyr_message was going to be needed.  Thus, it planned
for operating on the entire table and decided it could not use a more
efficient plan because work_mem, although large, would not be large
enough to execute the query over all of zephyr_message.

The original query was:

SELECT "zephyr_message"."id", "zephyr_message"."sender_id", "zephyr_message"."recipient_id", "zephyr_message"."subject", "zephyr_message"."content", "zephyr_message"."rendered_content", "zephyr_message"."rendered_content_version", "zephyr_message"."pub_date", "zephyr_message"."sending_client_id", "zephyr_userprofile"."id", "zephyr_userprofile"."password", "zephyr_userprofile"."last_login", "zephyr_userprofile"."email", "zephyr_userprofile"."is_staff", "zephyr_userprofile"."is_active", "zephyr_userprofile"."date_joined", "zephyr_userprofile"."full_name", "zephyr_userprofile"."short_name", "zephyr_userprofile"."pointer", "zephyr_userprofile"."last_pointer_updater", "zephyr_userprofile"."realm_id", "zephyr_userprofile"."api_key", "zephyr_userprofile"."enable_desktop_notifications", "zephyr_userprofile"."enter_sends", "zephyr_userprofile"."tutorial_status", "zephyr_realm"."id", "zephyr_realm"."domain", "zephyr_realm"."restricted_to_domain", "zephyr_recipient"."id", "zephyr_recipient"."type_id", "zephyr_recipient"."type", "zephyr_client"."id", "zephyr_client"."name" FROM "zephyr_message" INNER JOIN "zephyr_userprofile" ON ( "zephyr_message"."sender_id" = "zephyr_userprofile"."id" ) INNER JOIN "zephyr_realm" ON ( "zephyr_userprofile"."realm_id" = "zephyr_realm"."id" ) INNER JOIN "zephyr_recipient" ON ( "zephyr_message"."recipient_id" = "zephyr_recipient"."id" ) INNER JOIN "zephyr_client" ON ( "zephyr_message"."sending_client_id" = "zephyr_client"."id" ) ORDER BY "zephyr_message"."id" DESC LIMIT 25000;

with query plan:
 Limit  (cost=0.00..27120.95 rows=25000 width=362) (actual time=0.051..1121.282 rows=25000 loops=1)
   ->  Nested Loop  (cost=0.00..5330872.99 rows=4913981 width=362) (actual time=0.048..1081.014 rows=25000 loops=1)
         ->  Nested Loop  (cost=0.00..3932643.31 rows=4913981 width=344) (actual time=0.042..926.398 rows=25000 loops=1)
               ->  Nested Loop  (cost=0.00..2550275.29 rows=4913981 width=334) (actual time=0.035..752.524 rows=25000 loops=1)
                     Join Filter: (zephyr_message.sending_client_id = zephyr_client.id)
                     ->  Nested Loop  (cost=0.00..1739467.29 rows=4913981 width=320) (actual time=0.024..217.348 rows=25000 loops=1)
                           ->  Index Scan Backward using zephyr_message_pkey on zephyr_message  (cost=0.00..362510.09 rows=4913981 width=156) (actual time=0.014..42.097 rows=25000 loops=1)
                           ->  Index Scan using zephyr_userprofile_pkey on zephyr_userprofile  (cost=0.00..0.27 rows=1 width=164) (actual time=0.003..0.004 rows=1 loops=25000)
                                 Index Cond: (id = zephyr_message.sender_id)
                     ->  Materialize  (cost=0.00..1.17 rows=11 width=14) (actual time=0.001..0.010 rows=11 loops=25000)
                           ->  Seq Scan on zephyr_client  (cost=0.00..1.11 rows=11 width=14) (actual time=0.002..0.010 rows=11 loops=1)
               ->  Index Scan using zephyr_recipient_pkey on zephyr_recipient  (cost=0.00..0.27 rows=1 width=10) (actual time=0.002..0.003 rows=1 loops=25000)
                     Index Cond: (id = zephyr_message.recipient_id)
         ->  Index Scan using zephyr_realm_pkey on zephyr_realm  (cost=0.00..0.27 rows=1 width=18) (actual time=0.002..0.003 rows=1 loops=25000)
               Index Cond: (id = zephyr_userprofile.realm_id)
 Total runtime: 1141.408 ms

In the new code, we do two queries:

SELECT "zephyr_message"."id" FROM "zephyr_message" ORDER BY "zephyr_message"."id" DESC LIMIT 1

followed by:

SELECT "zephyr_message"."id", "zephyr_message"."sender_id", "zephyr_message"."recipient_id", "zephyr_message"."subject", "zephyr_message"."content", "zephyr_message"."rendered_content", "zephyr_message"."rendered_content_version", "zephyr_message"."pub_date", "zephyr_message"."sending_client_id", "zephyr_userprofile"."id", "zephyr_userprofile"."password", "zephyr_userprofile"."last_login", "zephyr_userprofile"."email", "zephyr_userprofile"."is_staff", "zephyr_userprofile"."is_active", "zephyr_userprofile"."date_joined", "zephyr_userprofile"."full_name", "zephyr_userprofile"."short_name", "zephyr_userprofile"."pointer", "zephyr_userprofile"."last_pointer_updater", "zephyr_userprofile"."realm_id", "zephyr_userprofile"."api_key", "zephyr_userprofile"."enable_desktop_notifications", "zephyr_userprofile"."enter_sends", "zephyr_userprofile"."tutorial_status", "zephyr_realm"."id", "zephyr_realm"."domain", "zephyr_realm"."restricted_to_domain", "zephyr_recipient"."id", "zephyr_recipient"."type_id", "zephyr_recipient"."type", "zephyr_client"."id", "zephyr_client"."name" FROM "zephyr_message" INNER JOIN "zephyr_userprofile" ON ( "zephyr_message"."sender_id" = "zephyr_userprofile"."id" ) INNER JOIN "zephyr_realm" ON ( "zephyr_userprofile"."realm_id" = "zephyr_realm"."id" ) INNER JOIN "zephyr_recipient" ON ( "zephyr_message"."recipient_id" = "zephyr_recipient"."id" ) INNER JOIN "zephyr_client" ON ( "zephyr_message"."sending_client_id" = "zephyr_client"."id" ) WHERE "zephyr_message"."id" > 4941883

with the message id filled in as the result of the first query.  The
new query differs from the original only in that its ORDER BY and
LIMIT clauses are replaced by a WHERE clause.  The second query has
query plan:

 Hash Join  (cost=709.30..28048.18 rows=20544 width=365) (actual time=41.678..279.261 rows=25041 loops=1)
   Hash Cond: (zephyr_message.recipient_id = zephyr_recipient.id)
   ->  Hash Join  (cost=102.98..27056.66 rows=20544 width=355) (actual time=3.686..190.730 rows=25041 loops=1)
         Hash Cond: (zephyr_message.sending_client_id = zephyr_client.id)
         ->  Hash Join  (cost=101.73..26772.94 rows=20544 width=341) (actual time=3.649..143.695 rows=25041 loops=1)
               Hash Cond: (zephyr_userprofile.realm_id = zephyr_realm.id)
               ->  Hash Join  (cost=99.99..26488.71 rows=20544 width=323) (actual time=3.578..96.746 rows=25041 loops=1)
                     Hash Cond: (zephyr_message.sender_id = zephyr_userprofile.id)
                     ->  Index Scan using zephyr_message_pkey on zephyr_message  (cost=0.00..26106.24 rows=20544 width=159) (actual time=0.017..41.980 rows=25041 loops=1)
                           Index Cond: (id > 4941883)
                     ->  Hash  (cost=83.33..83.33 rows=1333 width=164) (actual time=3.548..3.548 rows=1333 loops=1)
                           Buckets: 1024  Batches: 1  Memory Usage: 275kB
                           ->  Seq Scan on zephyr_userprofile  (cost=0.00..83.33 rows=1333 width=164) (actual time=0.006..1.646 rows=1333 loops=1)
               ->  Hash  (cost=1.33..1.33 rows=33 width=18) (actual time=0.064..0.064 rows=33 loops=1)
                     Buckets: 1024  Batches: 1  Memory Usage: 2kB
                     ->  Seq Scan on zephyr_realm  (cost=0.00..1.33 rows=33 width=18) (actual time=0.003..0.033 rows=33 loops=1)
         ->  Hash  (cost=1.11..1.11 rows=11 width=14) (actual time=0.027..0.027 rows=11 loops=1)
               Buckets: 1024  Batches: 1  Memory Usage: 1kB
               ->  Seq Scan on zephyr_client  (cost=0.00..1.11 rows=11 width=14) (actual time=0.003..0.013 rows=11 loops=1)
   ->  Hash  (cost=335.03..335.03 rows=21703 width=10) (actual time=37.974..37.974 rows=21761 loops=1)
         Buckets: 4096  Batches: 1  Memory Usage: 893kB
         ->  Seq Scan on zephyr_recipient  (cost=0.00..335.03 rows=21703 width=10) (actual time=0.004..18.443 rows=21761 loops=1)
 Total runtime: 299.300 ms

(imported from commit b2a70cccc47be7970df407c6be00eccd2e8be82a)
2013-04-25 13:25:15 -04:00
Tim Abbott 102988e430 Refill the Session cache after restarting the server.
The fact that we were dumping this cache and not refilling it seems to
be one of the causes of Tornado restarts being a lot slower on prod
than on local systems.

(imported from commit a32a759f4dfb591706ede1cce2d38f5c3704193c)
2013-04-24 10:44:56 -04:00
Tim Abbott 9b8f0fab0f Retrieve message objects from memcached in a bulk request.
On my laptop, this saves about 80 milliseconds per 1000 messages
requested via get_old_messages queries.  Since we only have one
memcached process and it does not run with special priority, this
might have significant impact on load during server restarts.

(imported from commit 06ad13f32f4a6d87a0664c96297ef9843f410ac5)
2013-04-24 10:44:56 -04:00
Tim Abbott 66b3c1fbff Log time spent querying memcached in logs when larger than 5ms.
(imported from commit a4de15026d24526a446b724500d1194dce824d1a)
2013-04-24 10:44:56 -04:00
Tim Abbott 5e22778843 Use a function for stopping/restarting time logging for longpolling.
(imported from commit 11b772deaa126fcc7e7605d467022b22d9e98cb0)
2013-04-24 10:44:56 -04:00
Waseem Daher 20233cfc96 Time out on Twitter rendering if it takes too long.
Timing out within the Twitter portion of the render causes the message
to still go through (without a preview). If we don't timeout here, it
causes the entire Markdown render to timeout, which rejects the
message in its entirety -- a far worse outcome.

(imported from commit f510a56f48afa46da8ec6277496fa03374cdb042)
2013-04-23 12:56:34 -04:00
Luke Faraone 71a91197fa Enable absolute imports.
See PEP 328[1] for details. This feature was introduced in Python 2.5 and
will become mandatory in Python 3.

[1]: http://www.python.org/dev/peps/pep-0328

(imported from commit 7444eeba8a08d5f91b94c7921848f2274979bd76)
2013-04-23 09:51:17 -07:00
Leo Franchi 7b0423efc1 Use incr instead of gauge when sending events to drawAsInfinite to statsd
(imported from commit 08a4b6920c7a4a8f472f147ddce7c04710fe5c0a)
2013-04-19 09:56:41 -04:00
Leo Franchi 652b821d64 Add a bunch of statsd logging
(imported from commit 8c17a76fed08c34abab3cc45d76a0fb30774d73a)
2013-04-18 18:05:52 -04:00