Merge lp:~gmb/launchpad/fix-subscribe-form-preloading-bug-722450 into lp:launchpad

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 12496
Proposed branch: lp:~gmb/launchpad/fix-subscribe-form-preloading-bug-722450
Merge into: lp:launchpad
Diff against target: 69 lines (+20/-5)
1 file modified
lib/lp/bugs/javascript/bugtask_index_portlets.js (+20/-5)
To merge this branch: bzr merge lp:~gmb/launchpad/fix-subscribe-form-preloading-bug-722450
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+51510@code.launchpad.net

Commit message

[r=benji][ui=none] [r=benji][bug=722450] The advanced direct bug subscription overlay's content is now loaded in the onClick handler for the Subscribe link rather than being loaded with every bug page load, which added unnecessary load to the server.

Description of the change

This branch is a minor JS refactoring to prevent the advanced subscription overlay from being loaded with every page load, which as lifeless pointed out increases server load unnecessarily.

The fix for this was to move the code that fetches the form content for the overlay into a function that is called in the onClick handler for the "Subscribe" link. This also means that we can do away with reloading the form content after the user has made a change to their subscription, saving us another unnecessary page load.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good. The only suggestion I have is that I suspect
that users would have a slightly better experience if we hypnotize them
with a spinner so they don't notice the passage of time while we do the
HTTP request to populate the form overlay.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/javascript/bugtask_index_portlets.js'
2--- lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-02-24 00:23:04 +0000
3+++ lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-02-28 16:12:21 +0000
4@@ -287,7 +287,8 @@
5 subscription.set('is_team', false);
6 var parent = e.target.get('parentNode');
7 if (namespace.use_advanced_subscriptions) {
8- subscription_overlay.show();
9+ load_and_show_advanced_subscription_overlay(
10+ subscription, subscription_overlay);
11 } else {
12 // Look for the false conditions of subscription, which
13 // is_direct_subscription, etc. don't report correctly,
14@@ -495,7 +496,6 @@
15 * @param subscription {Object} A Y.lp.bugs.subscriber.Subscription object.
16 */
17 function setup_advanced_subscription_overlay(subscription) {
18- subscription.enable_spinner("Loading...");
19 var subscription_overlay = new Y.lazr.FormOverlay({
20 headerContent: '<h2>Subscribe to bug</h2>',
21 form_submit_button:
22@@ -505,7 +505,23 @@
23 centered: true,
24 visible: false
25 });
26+ subscription_overlay.render('#privacy-form-container');
27+ return subscription_overlay;
28+}
29
30+/*
31+ * Load the content for and display the advanced subscription overlay.
32+ * The call to show() the overlay happens in the success handler for
33+ * loading the form content. That way the overlay won't appear empty.
34+ *
35+ * @method load_and_show_advanced_subscription_overlay
36+ * @param subscription {Object} A Y.lp.bugs.subscriber.Subscription object.
37+ * @param subscription_overlay {Object} A Y.lazr.FormOverlay to load
38+ * content into.
39+ */
40+function load_and_show_advanced_subscription_overlay(subscription,
41+ subscription_overlay) {
42+ subscription.enable_spinner('Loading...');
43 var subscription_link_url = subscription.get(
44 'link').get('href') + '/++form++';
45 subscription_overlay.set(
46@@ -525,6 +541,7 @@
47 subscription_overlay.renderUI();
48 subscription_overlay.bindUI();
49 subscription.disable_spinner();
50+ subscription_overlay.show();
51 }
52 function on_failure(id, response, subscription_overlay) {
53 subscription_overlay.set(
54@@ -532,14 +549,12 @@
55 "Sorry, an error occurred while loading the form.");
56 subscription_overlay.renderUI();
57 subscription.disable_spinner();
58+ subscription_overlay.show();
59 }
60 var config = {
61 on: {success: on_success, failure: on_failure},
62 }
63 Y.io(subscription_link_url, config);
64- subscription_overlay.render('#privacy-form-container');
65-
66- return subscription_overlay;
67 }
68
69 /*