Commit Graph

4079 Commits

Author SHA1 Message Date
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
Waseem Daher ccc5363f3c Make text-underneath-compose-box all nicely line up together.
(imported from commit d4676d95ccad18f65a29447647581b41d53dfa9a)
2013-04-24 17:49:45 -04:00
Luke Faraone 3bb3bbb1ee Redirect to /accounts/register relative to the current domain.
This ensures that we don't always send you to hhq.c when you use OpenID.

(imported from commit ab4c4cfa201740fbddcaa2e51bc15bfe977e221d)
2013-04-24 14:20:07 -07:00
Michael McCanna ce1389dc35 Remove double subscription when "creating" stream
When you create a stream that you'd previously created (then unsubscribed from),
it was possible to end up in the subscribers list twice. Once came from loading
the subscribers list from the backend, and once came from a bit of mark_subscribed
logic that only gets called if you've subscribed to that stream at least once before
in the current session.

resolves trac #1196

(imported from commit e47ff139a9c25b1b8689ea6795dfad96ae8d2591)
2013-04-24 16:21:14 -04:00
Waseem Daher bd702b777f Truncate long names in the presence list, rather than scrolling.
(imported from commit 6ba1487d5e2d2ac1435248fec5f161deec685180)
2013-04-24 15:53:54 -04:00
Allen Rabinovich f863a9b567 Added a check to filedrop plugin to check whether pasted content has strings.
If the pasted content has strings, we don't upload included files and instead
allow the default behavior to take place. This deals with a quirky behavior of
pastes from MS Word, which in addition to the formatted string content also
includes a thumbnail of it. Images still paste as usual.

(imported from commit 60c4f8dd90ac2e8e38940fb302cc9d1ebeecfdf3)
2013-04-24 12:33:16 -07:00
Luke Faraone 91b4e8d25d Add link to sign up with OpenID to the registration page.
Not that anybody visits that page.

(imported from commit 3102ffb4f6c952d94c4f4a7c90f381c6e0da51e5)
2013-04-24 12:03:42 -07:00
Luke Faraone b9fe130107 Add a comment to emphasise why we shouldn't break the HomepageForm.
(imported from commit 1b4d59e0c868e8350d2a9eb46cdfdaed1f34e69f)
2013-04-24 12:03:42 -07:00
Luke Faraone c48ff1784c Implement OpenID signups.
This allows users on signup-eligible domains to sign up for Humbug using
Google Apps.

As part of this, we wrap the openid done view in our own code in order to
handle the "Unknown user" error. Therein, we create a PreregistrationUser
and then shunt the user through the rest of the confirmation process, pre-
filling in their name.

(imported from commit 066d9a1021384a6da2662352e62a701451bd6f44)
2013-04-24 12:03:42 -07:00
Luke Faraone c044282af5 [third]: Accept and pass along gafyd_name parameters to confirmation templates.
This allows us to keep a record of the user's name as returned by Google
Apps authentication.

(imported from commit cbfe383a51b480400b8f0e5f40c725562ffc6a66)
2013-04-24 12:03:41 -07:00
Allen Rabinovich f8397e42c2 Adding an "Attach files" button to the message composition pane.
Changes include:
   * New markup for the button in compose.html
   * A hidden file input field in compose.html
   * Added reference to the file input field in filedrop
     initialization in compose.js
   * A feature test and a click event binding for
     the "Attach files" button in ui.js
   * New paperclip icon reference in fonts.css
   * New general hidden display classes in zephyr.css
   * New composition pane button classes in zephyr.css

Fixes to the "Attach files" button commit e673bda...

Changes include:
   * Fixed the feature test for (new XMLHttpRequest).upload so
     it works in Firefox.
   * Renamed .button to .message-control-button
   * Removed stray newlines

(imported from commit c1f0834b74fd7120ec27db64ec380ffb3fa34633)
2013-04-24 08:59:13 -07:00
Zev Benjamin 75bbda1dad Add lower message id bound when marking messages as read for the mobile unread count hack
Having a message ID range significantly improves the query
performance because the number of messages Postgres has to consider
is much smaller.

(imported from commit 9b007457712f1c1502d526abea1b6fd742bd911d)
2013-04-24 11:30:24 -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 1c57956bf6 Avoid an unnecessary load_old_messages call on page load.
Previously, our check for whether we needed to call load_old_messages
a second time on page load to get up to the present caused us to
basically always do such a call.

(imported from commit b599041e8c0853b4c8c9ab2def6679142302523e)
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 5f28cf8e02 Restore tutorial's ability to see what you send.
The internal format of 'message' had changed, so prior to this commit,
the tutorial was receiving (a) internally inconsistent, and (b)
not-what-it-expected versions of the message.

(imported from commit 233b934e6b600bd59125d133fdf7443fd8f6bbf8)
2013-04-24 10:35:25 -04:00
Waseem Daher eab43f28f4 Properly compute the name of our tutorial stream server-side.
It's subtle, but the slice was in the wrong place and wasn't
actually truncating the stream name at all, so the client and
server disagreed about where the tutorial messages should go.

(It might be the case that we should accept the tutorial stream
name from the client directly, rather than computing it in two
places.)

(imported from commit 8273223f182e8ad36eaea1cbf75e1426fcfdfbab)
2013-04-24 10:32:30 -04:00
Waseem Daher c05c391c31 Use '===' instead of '==' to make the linter happy.
(imported from commit 6fee035ab4531d64ece6a49501f275c64e0f2265)
2013-04-24 10:32:30 -04:00
Waseem Daher 072cb2425b Update new-user text slightly.
(imported from commit c75ff167234d83715924ce30fa04896feb35b859)
2013-04-24 10:28:33 -04:00
Waseem Daher 5951c7eb00 Don't send tutorial timeout message if we're no longer running.
If the system was waiting for you to reply and you replied 'exit', the
tutorial would stop -- but our thing that was waiting for you to reply
would continue waiting. It would eventually timeout and send you the
heartbroken "I didn't hear from you so I stopped waiting" message.

Chances are, you were unsubscribed so you didn't see it, but we
should still just not send it.

(imported from commit 694e442bc29b32efd59f08b4b8b5f573768aea21)
2013-04-24 10:28:33 -04:00
Jeff Arnold a251b12ec7 Don't trigger two events when our app changes the hash
(imported from commit c17a82b043c10927de149b105c6ceea5175b6f4f)
2013-04-23 16:13:26 -04:00
Jeff Arnold 0b9e509f41 If the user expanded a message, keep it expanded when we narrow
(imported from commit cbff6a8629df25b0b5b90bf6e10e9ea35e9a72ef)
2013-04-23 16:13:26 -04:00
Jeff Arnold 0c657f6fc5 Process collapsing every time we show new content
(imported from commit 21899206e9012023d3fec08f3990474fa38047e7)
2013-04-23 16:13:26 -04:00
Jeff Arnold 1cf946969d Fix name of hashchange.zephyr event in changehash
tabbott noticed this mistake during some pair programming

(imported from commit 3b5885f50929e3ed0062eef4e5f3aba0a14d52bc)
2013-04-23 16:13:26 -04:00
Tim Abbott c4e4b481bd Increase the threshhold for triggering collapsing./
(imported from commit c09b5ac43b4521bcbb2ab3feb5334fc9cf9ba1a5)
2013-04-23 16:13:26 -04:00
Jeff Arnold 3f68ff3ac3 Don't collapse messages that would only be collapsed by a small amount
(imported from commit 2cdd1ef1c731c7e6ac122f431ccf91d41d8f9234)
2013-04-23 16:13:26 -04:00
Zev Benjamin a398eff891 Center the message condenser messages with respect to the message body
Previously it was centered with respect to its enclosing div, which
looked slightly off.

(imported from commit 3878f162d3eb50ce85cae7054102095069aa60c8)
2013-04-23 16:13:26 -04:00
Jeff Arnold 70e5bd4049 Automatically condense long messages
Addresses Trac #747.

(imported from commit 4ddf2d8773023805650f04924be62da2d0fe826e)
2013-04-23 16:13:26 -04:00
Waseem Daher 5b1aed7022 Rename "Your messages" to home, and give everything an icon.
Pretty hackish for now since this is presumably going to all
be redone with Font Awesome icons in not too long.

(imported from commit 497d6cf18d7a8d6014a20c08d66d88c324478e55)
2013-04-23 15:14:45 -04:00
Michael McCanna bd00e2609e add mouse movement as a trigger to stop autoscroll
(imported from commit 746bab4983d8267e5c37c0232f04e2c8f9f06e2d)
2013-04-23 13:23:07 -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
Tim Abbott 71203a996a Fix autoscrolling on new messages.
This was apparently broken by the final revision of our fix to the
autoscrolling+narrow bugs, because it attempted to use jquery's
animation queues to restrict which animations were stopped, and this
doesn't seem to work.

(imported from commit cf97f9f56dc5a16d1aa0322b5e6ec432a76d3be2)
2013-04-23 12:54:59 -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 b1dd0ae09c [jquery.filedrop] Browser compatibility fixes for quirky browsers
Don't assume clipboardData.items since it doesn't exist on Safari
Make sure there are no files if using a clipboard drop. Safari includes a blank text/uri-list
 data entry
Firefox fix for image pasting

(imported from commit ea0d56fe73ca45cf2e4d437df23a4023bb649445)
2013-04-22 19:51:29 -04:00
Leo Franchi 222b603b09 Elide subject names in sidebar
(imported from commit a0d75e03757251b8fcb69de6ff7239f899bf8974)
2013-04-22 17:22:06 -04:00
Zev Benjamin af3ef8636c puppet: Add Postgres recovery.conf
Note that this file needs to be copied over manually as part of the
process of starting up a new replica.

(imported from commit a9f14b695ef2b6b4d48b6180d187c3babf5a667c)
2013-04-22 16:36:09 -04:00
Zev Benjamin 986ca06c44 puppet: Add wal-e to Postgres config
(imported from commit 55727a95cc51afb69f14c27df89a6ae287ec0f3f)
2013-04-22 16:36:09 -04:00
Zev Benjamin f280e7cdfa puppet: Use deadline scheduler for disks on Postgres master
(imported from commit 41061cb4535b94b4afea8c3a2228120073bf06ee)
2013-04-22 16:36:09 -04:00
Zev Benjamin 092cdff061 puppet: Log Postgres checkpoint information
(imported from commit 41603ad1c3cf8419d315b44d5679e0817062ced0)
2013-04-22 16:36:09 -04:00
Zev Benjamin 387f63deaa puppet: Add vm sysctl settings to Postgres configs
(imported from commit e557815f490a603da635fb60d39569346a72aa85)
2013-04-22 16:36:09 -04:00
Zev Benjamin a13b929d1f puppet: Add script to configure Postgres master disks
(imported from commit 61004aa839df8f3fa82ba0c4ea9e2a01ae43464c)
2013-04-22 16:36:09 -04:00
Zev Benjamin e7cdea1c43 puppet: Tweak Postgres master tunables for its hardware
(imported from commit 8644e82d00944203728a3214b2141f778e1c54ed)
2013-04-22 16:36:09 -04:00
Zev Benjamin 336db5c709 puppet: Split Postgres puppet config into master and slave versions
(imported from commit adb02cc1904875eb8f56fe272b44dd51bb7d939d)
2013-04-22 16:36:09 -04:00
Tim Abbott 4e03ed0b7e Fix narrows_by_subject treatment when a private message is selected.
Previously, we were calling util.same_stream_and_subject on a pair of
messages, one of which was a private message, which is not valid.  We
should have instead been calling util.same_recipient, which checks the
message type as well.

(imported from commit bc5715807036bff1fd4f214dafad00e33678e91d)
2013-04-22 16:21:34 -04:00
Zev Benjamin 41e2bd3f40 blueslip: Fix BlueslipError definition
This fixes a problem where normal exceptions weren't triggering
blueslip.

(imported from commit 1cc0f8bcf0676eb2aa34ebd74d93af29251c5823)
2013-04-22 16:04:51 -04:00
Waseem Daher fba9ae983c integrations: Remove unused Jenkins images.
(imported from commit 6e88b4e050b217e2dd6a1201e08b5d71145d2e67)
2013-04-22 11:48:25 -04:00
Waseem Daher 84443310df integrations: Simplify the Jenkins installation instructions.
(imported from commit 612070ccef7f1637a093503fa2e902c540b00a8e)
2013-04-22 11:48:25 -04:00
Tim Abbott 26b0eb341e Fade around new recipient when restoring a draft.
(imported from commit 7888ae124bfba150b354ba27cb12c99364b43263)
2013-04-22 11:14:56 -04:00