Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4Wnt-0000wI-F7 for pgadmin-hackers@arkaria.postgresql.org; Fri, 06 Apr 2018 19:13:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f4Wns-0003cC-3d for pgadmin-hackers@arkaria.postgresql.org; Fri, 06 Apr 2018 19:13:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4Wnr-0003c2-Ij for pgadmin-hackers@lists.postgresql.org; Fri, 06 Apr 2018 19:13:39 +0000 Received: from mail-it0-x22f.google.com ([2607:f8b0:4001:c0b::22f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f4Wnm-0004db-45 for pgadmin-hackers@postgresql.org; Fri, 06 Apr 2018 19:13:37 +0000 Received: by mail-it0-x22f.google.com with SMTP id x144-v6so5866522itc.0 for ; Fri, 06 Apr 2018 12:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pivotal-io.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=etaAMwQ5jjDcgO4az14oYEbYxpoIcjoEhO8RJ/XZsqI=; b=ea2mdV/HMW20lx+rwNRZeTKaewx0M4Lq1BlVIt4ycfgLz7AqVoMnQ0rmhcz+IKP6yt NwwHRYNIYJZXug0oHFpJ/GYLcEvxKYsUDJkpf1bfrupz9I3Kj8X9dhm8cU6E7jKFWIlQ Q+NEvcQFJgx5UN8e2tYbKZwA+JpPKWIlS0TcLLUKew1CnhKyeUTTYvpxfyRyZ1rFwgXW 5YRm9d1so9PNPiD6diSZw2ZhJoW1pb1RYTj4KvbLejSLUg83Lm9JqtGZwAzyFDkkZnnZ 0R3MdLZdKG3uhww4nuzSnr8rvJ7Df5jyDRVur8FnwtKyQWEhPLNP9QbftxX0uiw8TqX0 b4aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=etaAMwQ5jjDcgO4az14oYEbYxpoIcjoEhO8RJ/XZsqI=; b=VQvz9jVaN+AMQ+2Q7boOIUVCzGQSYZV24KysxnDnRWQ8RvKiUhmbSaiV7VdFBZQOaJ /YYILyHAdKg/ynK3duS7HuH4YGHWGi9QoWfIWUFXcYssGToW4n/Lw4AYSZcIO6vkwU+d gws5touChqOrGD0RXnRWvlcbqWULVOiJ1VNr4giECQOfUJb/W0iX1FbDfYh86qsDQ/Po yhmHS6iOpKli0if6cGgCmPD99S8M8TDBFHM+iO9+yBb3WOm1uz6Q4nB5Uy06DlZcuja3 cbH6nIGFaWeCHtptBRZdsAqkfXDOosZH0bHQ030XZUpwmSrKkRj3USOs0zLEoznxD4Q6 dWgA== X-Gm-Message-State: ALQs6tDos08i9JaT1wzjT4DhkbLXStUKbt6y2WjhVPf0ao9KkVH6PJ0Q 2TYGv5dJfyOA2hxn+snW9XQDqhrD8V8L/jRFtJ3xdg== X-Google-Smtp-Source: AIpwx4+1hDxpQywh+EmEAe51DIxJcEFcjPRoW/95VdTPv98dv+Xxd702zaqHpTnC5JECx4HnHPH8R1V9nmDNs1phJx0= X-Received: by 2002:a24:2d0a:: with SMTP id x10-v6mr17091451itx.95.1523042012575; Fri, 06 Apr 2018 12:13:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Joao De Almeida Pereira Date: Fri, 06 Apr 2018 19:13:22 +0000 Message-ID: Subject: Re: [pgadmin4][patch] Initial patch to decouple from ACI Tree To: Murtuza Zabuawala Cc: Khushboo Vashi , pgadmin-hackers Content-Type: multipart/alternative; boundary="000000000000236f87056932da76" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000236f87056932da76 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Murtuza/Dave, Yes now the extracted functions are spread into different files. The intent would be to make the files as small as possible, and also to group and name them in a way that would be easy to understand what each file is doing without the need of opening it. As a example: static/js/backup will contain all the backup related functionality inside of this folder we can see the file: menu_utils.js At this moment in time we decided to group all the functions that are related to the menu, but we can split that also if we believe it is easier to see. static/js/datagrid folder contains all the datagrid related functionality Inside of the folder we can see the files: get_panel_title.js is responsible for retrieving the name of the panel show_data.js is responsible for showing the datagrid show_query_tool.js is responsible for showing the query tool Does this structure make sense? Can you give an example of a comment that you think is missing and that could help? As a personal note, unless the algorithm is very obscure or very complicated, I believe that if the code needs comments it is a signal that something needs to change in terms of naming, structure of the part in question. This being said, I am open to add some comments that might help people. Thanks Joao =E2=80=8B On Fri, Apr 6, 2018 at 4:48 AM Murtuza Zabuawala < murtuza.zabuawala@enterprisedb.com> wrote: > Hi Joao, > > Patch looks good and working as expected. > > I also agree with Dave, Can we please add some comments in each file whic= h > can help us to understand the flow, I'm saying because now the code is > segregated in so many separate files it will be hard to keep track of the > flow from one file to another when debugging. > > > -- > Regards, > Murtuza Zabuawala > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > > > On Thu, Apr 5, 2018 at 7:08 PM, Joao De Almeida Pereira < > jdealmeidapereira@pivotal.io> wrote: > >> Hi Khushboo, >> Attached you can find both patches rebased >> >> Thanks >> >> >> On Thu, Apr 5, 2018 at 6:31 AM Khushboo Vashi < >> khushboo.vashi@enterprisedb.com> wrote: >> >>> Hi Joao, >>> >>> Can you please rebase the second patch? >>> >>> Thanks, >>> Khushboo >>> >>> >>> On Tue, Apr 3, 2018 at 12:15 AM, Joao De Almeida Pereira < >>> jdealmeidapereira@pivotal.io> wrote: >>> >>>> Hi Hackers, >>>> >>>> Attached you can find the patch that will start to decouple pgAdmin >>>> from ACITree library. >>>> This patch is intended to be merged after 3.0, because we do not want >>>> to cause any entropy or delay the release, but we want to start the >>>> discussion and show some code. >>>> >>>> This job that we started is a massive tech debt chore that will take >>>> some time to finalize and we would love the help of the community to d= o it. >>>> >>>> *Summary of the patch:* >>>> 0001 patch: >>>> - Creates a new tree that will allow us to create a separation betwee= n >>>> the application and ACI Tree >>>> - Creates a Fake Tree (Test double, for reference on the available >>>> test doubles: https://martinfowler.com/bliki/TestDouble.html) that can >>>> be used to inplace to replace the ACITree and also encapsulate the new= tree >>>> behavior on our tests >>>> - Adds tests for all the tree functionalities >>>> >>>> 0002 patch: >>>> - Extracts, refactors, adds tests and remove dependency from ACI Tree >>>> on: >>>> - getTreeNodeHierarchy >>>> - on backup.js: menu_enabled, menu_enabled_server, >>>> start_backup_global_server, backup_objects >>>> - on datagrid.js: show_data_grid, get_panel_title, show_query_tool >>>> - Start using sprintf-js as Underscore.String is deprecating sprintf >>>> function >>>> >>>> This patch represents only 10 calls to ACITree.itemData out of 176 tha= t >>>> are spread around our code >>>> >>>> >>>> *In Depth look on the process behind the patch:* >>>> >>>> We started writing this patch with the idea that we need to decouple >>>> pgAdmin4 from ACITree, because ACITree is no longer supported, the >>>> documentation is non existent and ACITree is no longer being actively >>>> developed. >>>> >>>> Our process: >>>> 1. We "randomly" selected a function that is part of the ACITree. From >>>> this point we decided to replace that function with our own version. T= he >>>> function that we choose was "itemData". >>>> The function gives us all the "data" that a specific node of the tree >>>> find. >>>> Given in order to replace the tree we would need to have a function >>>> that would give us the same information. We had 2 options: >>>> a) Create a tree with a function called itemData >>>> Pros: >>>> - At first view this was the simpler solution >>>> - Would keep the status quo >>>> Cons: >>>> - Not a OOP approach >>>> - Not very flexible >>>> b) Create a tree that would return a node given an ID and then the >>>> node would be responsible for giving it's data. >>>> Pros: >>>> - OOP Approach >>>> - More flexible and we do not need to bring the tree around, just a >>>> node >>>> Cons: >>>> - Break the current status quo >>>> >>>> Given these 2 options we decided to go for a more OOP approach creatin= g >>>> a Tree and a TreeNode classes, that in the future will be renamed to >>>> ACITreeWrapper and TreeNode. >>>> >>>> 2. After we decided on the starting point we searched for occurrences >>>> of the function "itemData" and we found out that there were 303 occurr= ences >>>> of "itemData" in the code and roughly 176 calls to the function itself >>>> (some of the hits were variable names). >>>> >>>> 3. We selected the first file on the search and found the function tha= t >>>> was responsible for calling the itemData function. >>>> >>>> 4. Extracted the function to a separate file >>>> >>>> 5. Wrap this function with tests >>>> >>>> 6. Refactor the function to ES6, give more declarative names to >>>> variables and break the functions into smaller chunks >>>> >>>> 7. When all the tests were passing we replaced ACITree with our Tree >>>> >>>> 8. We ensured that all tests were passing >>>> >>>> 9. Remove function from the original file and use the new function >>>> >>>> 10. Ensure everything still works >>>> >>>> 11. Find the next function and execute from step 4 until all the >>>> functions are replaced, refactored and tested. >>>> >>>> As you can see by the process this is a pretty huge undertake, because >>>> of the number of calls to the function. This is just the first step on= the >>>> direction of completely isolating the ACITree so that we can solve the >>>> problem with a large number of elements on the tree. >>>> >>>> *What is on our radar that we need to address:* >>>> - Finish the complete decoupling of the ACITree >>>> - Performance of the current tree implementation >>>> - Tweak the naming of the Tree class to explicitly tell us this is to >>>> use only with ACITree. >>>> >>>> >>>> Thanks >>>> Joao >>>> >>>> >>> > --000000000000236f87056932da76 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hello Murtuza/Dave,
Yes now the extr= acted functions are spread into different files. The intent would be to mak= e the files as small as possible, and also to group and name them in a way = that would be easy to understand what each file is doing without the need o= f opening it.
As a example:
static/js/backup = will contain all the backup related functionality
inside of this folder = we can see the file:
menu_utils.js At this momen= t in time we decided to group all the functions that are related to the men= u, but we can split that also if we believe it is easier to see.

static/js/data= grid folder contains all the datagrid related functionality
Insid= e of the folder we can see the files:
get_panel_title.j= s is responsible for retrieving the name of the panel
show_data.js is responsible for showing the datagrid
show_query_tool.js is responsible for showing the query t= ool

Does this structure make sense?=
Can you give an example of a comment that you think is missing and that= could help?

As a personal note, unless the = algorithm is very obscure or very complicated, I believe that if the code n= eeds comments it is a signal that something needs to change in terms of nam= ing, structure of the part in question. This being said, I am open to add s= ome comments that might help people.

Thanks
Joao

=E2=80=8B


<= div class=3D"gmail_quote">
On Fri, Apr 6, 2018 at 4:48 AM M= urtuza Zabuawala <= murtuza.zabuawala@enterprisedb.com> wrote:
Hi Joao,

<= div class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;color:#= 444444">Patch looks good and working as expected.

<= div class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;color:#= 444444">I also agree with Dave, Can we please add some comments in each fil= e which can help us to understand the flow, I'm saying because now the = code is segregated in so many separate files it will be hard to keep track = of the flow from one file to another when debugging.


--
Regards,
Murtuza Zabuawala
= EnterpriseDB:=C2=A0http://www.enterprisedb.com
The Enterprise Pos= tgreSQL Company


On Thu, Apr 5, 2018 at 7:08 PM, Joao De Alme= ida Pereira <jdealmeidapereira@pivotal.io> wrote:=
Hi Khushboo,
Attach= ed you can find both patches rebased

Thanks
<= div>

On Thu, Apr 5= , 2018 at 6:31 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrot= e:
Hi Joao,
Can you please rebase the second patch?

Thanks,
Khushboo


On Tue, Apr 3, 2018 at 12= :15 AM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi = Hackers,

Attached you can find the patch that will start= to decouple pgAdmin from ACITree library.
This patch is intended= to be merged after 3.0, because we do not want to cause any entropy or del= ay the release, but we want to start the discussion and show some code.

This job that we started is a massive tech debt chore= that will take some time to finalize and we would love the help of the com= munity to do it.

Summary of the patch:
0001 patch:=C2=A0
=C2=A0- Creates a new tree that will allo= w us to create a separation between the application and ACI Tree
= =C2=A0- Creates a Fake Tree (Test double, for reference on the available te= st doubles:=C2=A0https://martinfowler.com/bliki/TestDouble.html) that= can be used to inplace to replace the ACITree and also encapsulate the new= tree behavior on our tests
=C2=A0- Adds tests for all the tree f= unctionalities

0002 patch:
=C2=A0- Extra= cts, refactors, adds tests and remove dependency from ACI Tree on:
= - getTreeNodeHierarchy
- on backup.js: menu_enabled, menu_enabled_s= erver, start_backup_global_server, backup_objects
- on datagrid.js: = show_data_grid, get_panel_title, show_query_tool
- Start using sprintf-= js as Underscore.String is deprecating sprintf function
=C2=A0=C2= =A0
This patch represents only 10 calls to ACITree.itemData out o= f 176 that are spread around our code


<= /div>
In Depth look on the process behind the patch:
<= br>
We started writing this patch with the idea that we need to d= ecouple pgAdmin4 from ACITree, because ACITree is no longer supported, the = documentation is non existent and ACITree is no longer being actively devel= oped.

Our process:
1. We "randomly&= quot; selected a function that is part of the ACITree. From this point we d= ecided to replace that function with our own version. The function that we = choose was "itemData".
The function gives us all the &q= uot;data" that a specific node of the tree find.
Given in or= der to replace the tree we would need to have a function that would give us= the same information. We had 2 options:
=C2=A0 a) Create a tree = with a function called itemData
Pros:
=C2=A0- At first = view this was the simpler solution
=C2=A0- Would keep the status quoCons:
=C2=A0- Not a OOP approach
=C2=A0- Not very fl= exible
=C2=A0 b) Create a tree that would return a node given an = ID and then the node would be responsible for giving it's data.
Pros:=C2=A0
=C2=A0- OOP Approach
=C2=A0- More flexib= le and we do not need to bring the tree around, just a node
Cons:=
=C2=A0- Break the current status quo

Gi= ven these 2 options we decided to go for a more OOP approach creating a Tre= e and a TreeNode classes, that in the future will be renamed to ACITreeWrap= per and TreeNode.

2. After we decided on the start= ing point we searched for occurrences of the function "itemData" = and we found out that there were 303 occurrences of "itemData" in= the code and roughly 176 calls to the function itself (some of the hits we= re variable names).

3. We selected the first file = on the search and found the function that was responsible for calling the i= temData function.

4. Extracted the function to a s= eparate file

5. Wrap this function with tests

6. Refactor the function to ES6, give more declarative= names to variables and break the functions into smaller chunks
<= br>
7. When all the tests were passing we replaced ACITree with o= ur Tree

8. We ensured that all tests were passing<= /div>

9. Remove function from the original file and use = the new function

10. Ensure everything still works=

11. Find the next function and execute from step = 4 until all the functions are replaced, refactored and tested.
As you can see by the process this is a pretty huge undertake,= because of the number of calls to the function. This is just the first ste= p on the direction of completely isolating the ACITree so that we can solve= the problem with a large number of elements on the tree.

What is on our radar that we need to address:
=C2= =A0- Finish the complete decoupling of the ACITree
=C2=A0- Perfor= mance of the current tree implementation
=C2=A0- Tweak the naming= of the Tree class to explicitly tell us this is to use only with ACITree.<= /div>


Thanks
Joao



--000000000000236f87056932da76--