Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/397904 )

Change subject: Avoid closing connections prematurely
......................................................................

Avoid closing connections prematurely

And make sure the results are returned
Also close in a few more places

Change-Id: I3e37b6f664f8893009d256b23dcde636dc03ea6b
---
M persistence.js
1 file changed, 20 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash 
refs/changes/04/397904/1

diff --git a/persistence.js b/persistence.js
index 6398d58..42b6d74 100644
--- a/persistence.js
+++ b/persistence.js
@@ -32,7 +32,12 @@
                values.push( board.id );
                values.push( i );
        }
-       return connection.query( insertWidgets + placeholders, values ).then( 
connection.end() );
+       return connection.query( insertWidgets + placeholders, values ).then(
+               function( dbResult ) {
+                       connection.end();
+                       return dbResult;
+               }
+       );
 }
 
 module.exports = {
@@ -93,12 +98,17 @@
                        } )
                        .then( function ( dbResults ) {
                                if ( !dbResults ) {
+                                       connection.end();
                                        return;
                                }
                                user.defaultBoard = dbResults[ 0 ][ 2 ][ 0 ].id;
-                               var result = connection.query( 
insertBigEnglish, [ userId ] )
-                                       .then( connection.end() );
-                               return result;
+                               return connection.query( insertBigEnglish, [ 
userId ] )
+                                       .then(
+                                               function( dbResult ) {
+                                                       connection.end();
+                                                       return dbResult;
+                                               }
+                                       );
                        } );
        },
        /**
@@ -119,6 +129,7 @@
                if ( instance.id ) {
                        return connection.query( update, updateParams )
                                .then( function ( dbResults ) {
+                                       connection.end();
                                        if ( dbResults[ 0 ].affectedRows !== 1 
) {
                                                // Either the instance doesn't 
exist or it's not ours
                                                throw new Error( 'Instance ' + 
instance.id + ' with owner ' + instance.ownerId + ' not found' );
@@ -218,15 +229,16 @@
 
                if ( board.id ) {
                        if ( board.addWidget ) {
-                               return connection.query( addWidget, 
addWidgetParams );
+                               return connection.query( addWidget, 
addWidgetParams ).then( connection.end );
                        }
                        if ( board.deleteWidget ) {
-                               return connection.query( deleteWidget, 
deleteWidgetParams );
+                               return connection.query( deleteWidget, 
deleteWidgetParams ).then( connection.end );
                        }
                        return connection.query( update, updateParams )
                                .then( function ( dbResults ) {
                                        if ( dbResults[ 0 ].affectedRows !== 1 
) {
                                                // Either the board doesn't 
exist or it's not ours
+                                               connection.end();
                                                throw new Error( 'Board ' + 
board.id + ' with owner ' + board.ownerId + ' not found' );
                                        }
                                } )
@@ -242,7 +254,7 @@
                                board.id = dbResults[ 0 ].insertId;
                        } )
                        .then( function () {
-                               return insertWidgetList( board, connection 
).then( connection.end() );
+                               return insertWidgetList( board, connection );
                        } );
        },
        /**
@@ -262,6 +274,7 @@
                                        widgetSelect = 'SELECT wi.id, 
wi.widget_id, w.code, wi.owner_id, wi.display_name, wi.description, 
wi.is_shared, wi.configuration FROM dash_widget_instance wi INNER JOIN 
dash_widget w on w.id = wi.widget_id INNER JOIN dash_widget_instance_board wib 
ON wi.id = wib.instance_id WHERE wib.board_id = ? ORDER BY wib.widget_position';
 
                                if ( !result.owner_id ) {
+                                       connection.end();
                                        throw new Error( 'Board ' + boardId + ' 
with owner ' + userId + ' not found' );
                                }
                                board = {

-- 
To view, visit https://gerrit.wikimedia.org/r/397904
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e37b6f664f8893009d256b23dcde636dc03ea6b
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to