#50068 Issue 50061 - Improve schema loading in UI
Closed 3 years ago by spichugi. Opened 5 years ago by spichugi.
spichugi/389-ds-base schema_loading  into  master

@@ -81,6 +81,7 @@ 

    $("#schema-list").prop('selectedIndex',-1);

    $('#oc-required-list').find('option').remove();

    $('#oc-allowed-list').find('option').remove();

+   $("#oc-x-origin").val("");

    $("#save-oc-button").attr('disabled', false);

  }

  
@@ -102,33 +103,26 @@ 

    $("#attr-eq-mr-select").prop('selectedIndex',0);

    $("#attr-order-mr-select").prop('selectedIndex',0);

    $("#attr-sub-mr-select").prop('selectedIndex',0);

+   $("#attr-x-origin").val("");

    $("#save-attr-button").attr('disabled', false);

  }

  

- function load_schema_objects_to_select(object, select_id) {

-   var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', object, 'list'];

-   log_cmd('load_schema_objects_to_select', 'Get schema', cmd);

-   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(select_data) {

-     var obj = JSON.parse(select_data);

-     var data = [];

-     for (var i = 0; i < obj.items.length; i++) {

-       item = obj.items[i];

-       if (item.name) {

-         data.push.apply(data, [item.name]);

-       } else {

-         data.push.apply(data, [item.oid]);

-       }

+ function load_schema_objects_to_select(object, select_id, schema_json_select) {

+   var data = [];

+   for (var i = 0; i < schema_json_select[object].items.length; i++) {

+     item = schema_json_select[object].items[i];

+     if (item.name) {

+       data.push.apply(data, [item.name]);

+     } else {

+       data.push.apply(data, [item.oid]);

      }

-     // Update html select

-     $.each(data, function (i, item) {

-         $("#" + select_id).append($('<option>', {

-             value: item,

-             text : item

-         }));

-     });

-   }).fail(function(select_data) {

-       console.log("Get schema failed: " + select_data.message);

-       check_inst_alive(1);

+   }

+   // Update html select

+   $.each(data, function (i, item) {

+       $("#" + select_id).append($('<option>', {

+           value: item,

+           text : item

+       }));

    });

  }

  
@@ -151,16 +145,16 @@ 

        }));

    });

  

-   // Setup the tables: standard, custom, and Matching Rules

-   var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'objectclasses', 'list'];

-   log_cmd('get_and_set_schema_tables', 'Get objectclasses', cmd);

-   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(oc_data) {

-     var obj = JSON.parse(oc_data);

+   var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'list'];

+   log_cmd('get_and_set_schema_tables', 'Get all schema objects', cmd);

+   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(schema_data) {

+     var schema_json = JSON.parse(schema_data);

+     // Setup the tables: standard, custom, and Matching Rules

      var data = [];

      // If objectClass is user defined them the action button is enabled

-     for (var i = 0; i < obj.items.length; i++) {

+     for (var i = 0; i < schema_json.objectclasses.items.length; i++) {

        var oc_btn = oc_btn_html_only_view;

-       item = obj.items[i];

+       item = schema_json.objectclasses.items[i];

        if (is_x_origin_user_defined(item.x_origin)) {

          oc_btn = oc_btn_html;

        }
@@ -218,46 +212,37 @@ 

          "visible": false

        }]

      });

-   }).fail(function(oc_data) {

-       console.log("Get objectclasses failed: " + oc_data.message);

-       check_inst_alive(1);

-   });

  

-   // Get syntaxes and use the data to populate the attribute's table

-   log_cmd('get_and_set_schema_tables', 'Get syntaxes', cmd);

-   cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', "attributetypes", 'get_syntaxes'];

-   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(syntax_data) {

-     var obj = JSON.parse(syntax_data);

-     var syntax_list = [];

- 

-     load_schema_objects_to_select('matchingrules', 'attr-eq-mr-select');

-     load_schema_objects_to_select('matchingrules', 'attr-order-mr-select');

-     load_schema_objects_to_select('matchingrules', 'attr-sub-mr-select');

-     load_schema_objects_to_select('attributetypes', 'schema-list');

-     load_schema_objects_to_select('objectclasses', 'oc-parent');

-     load_schema_objects_to_select('attributetypes', 'attr-parent');

- 

-     for (var i = 0; i < obj.items.length; i++) {

-       item = obj.items[i];

-       syntax_list.push.apply(syntax_list, [item]);

-     }

-     // Update syntax select html in attribute's edit window

-     $.each(syntax_list, function (i, item) {

-         $("#attr-syntax").append($('<option>', {

-             value: item.id,

-             text : item.name + " (" + item.id + ")"

-         }));

-     });

+     // Get syntaxes and use the data to populate the attribute's table

+     cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', "attributetypes", 'get_syntaxes'];

+     cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(syntax_data) {

+       var obj = JSON.parse(syntax_data);

+       var syntax_list = [];

+ 

+       load_schema_objects_to_select('matchingrules', 'attr-eq-mr-select', schema_json);

+       load_schema_objects_to_select('matchingrules', 'attr-order-mr-select', schema_json);

+       load_schema_objects_to_select('matchingrules', 'attr-sub-mr-select', schema_json);

+       load_schema_objects_to_select('attributetypes', 'schema-list', schema_json);

+       load_schema_objects_to_select('objectclasses', 'oc-parent', schema_json);

+       load_schema_objects_to_select('attributetypes', 'attr-parent', schema_json);

+ 

+       for (var i = 0; i < obj.items.length; i++) {

+         item = obj.items[i];

+         syntax_list.push.apply(syntax_list, [item]);

+       }

+       // Update syntax select html in attribute's edit window

+       $.each(syntax_list, function (i, item) {

+           $("#attr-syntax").append($('<option>', {

+               value: item.id,

+               text : item.name + " (" + item.id + ")"

+           }));

+       });

  

-     var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'attributetypes', 'list'];

-     log_cmd('get_and_set_schema_tables', 'Get attributes', cmd);

-     cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(at_data) {

-       var obj = JSON.parse(at_data);

        var data = [];

        var syntax_name = "";

-       for (var i = 0; i < obj.items.length; i++) {

+       for (var i = 0; i < schema_json.attributetypes.items.length; i++) {

          var attr_btn = attr_btn_html_only_view;

-         item = obj.items[i];

+         item = schema_json.attributetypes.items[i];

          if (item.single_value) {

              multivalued = 'no';

          } else {
@@ -340,23 +325,14 @@ 

            "visible": false

          }]

        });

-     }).fail(function(at_data) {

-         console.log("Get attributes failed: " + at_data.message);

+     }).fail(function(syntax_data) {

+         console.log("Get syntaxes failed: " + syntax_data.message);

          check_inst_alive(1);

      });

  

-   }).fail(function(syntax_data) {

-       console.log("Get syntaxes failed: " + syntax_data.message);

-       check_inst_alive(1);

-   });

- 

-   cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id + '.socket', 'schema', 'matchingrules', 'list'];

-   log_cmd('get_and_set_schema_tables', 'Get matching rules', cmd);

-   cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(mr_data) {

-     var obj = JSON.parse(mr_data);

      var data = [];

-     for (var i = 0; i < obj.items.length; i++) {

-       item = obj.items[i];

+     for (var i = 0; i < schema_json.matchingrules.items.length; i++) {

+       item = schema_json.matchingrules.items[i];

        data.push.apply(data, [[

          item.name,

          item.oid,
@@ -376,9 +352,8 @@ 

      });

  

      console.log("Finished loading schema.");

- 

-   }).fail(function(mr_data) {

-       console.log("Get matching rules failed: " + mr_data.cmd);

+   }).fail(function(oc_data) {

+       console.log("Get all schema objects failed: " + oc_data.message);

        check_inst_alive(1);

    });

  }
@@ -768,6 +743,8 @@ 

      $(document).on('click', '.attr-view-btn', function(e) {

        e.preventDefault();

        load_attr_form($(this));

+       var edit_attr_name = schema_at_table.row($(this).parents('tr') ).data()[0];

+       $("#add-edit-attr-header").html('View Attribute: ' + edit_attr_name);

        $("#save-attr-button").attr('title', 'Only user-defined attributes can be modified');

        $("#save-attr-button").attr('disabled', true);

      });
@@ -846,6 +823,8 @@ 

      $(document).on('click', '.oc-view-btn', function(e) {

        e.preventDefault();

        load_oc_form($(this));

+       var edit_oc_name = schema_oc_table.row($(this).parents('tr') ).data()[0];

+       $("#add-edit-oc-header").html('View Objectclass: ' + edit_oc_name);

        $("#save-oc-button").attr('title', 'Only user-defined objectClasses can be modified');

        $("#save-oc-button").attr('disabled', true);

      });
@@ -879,5 +858,3 @@ 

      schema_page_loaded = 1;

    });

  });

- 

- 

@@ -21,6 +21,35 @@ 

          return 0

  

  

+ def list_all(inst, basedn, log, args):

+     log = log.getChild('list_all')

+     schema = Schema(inst)

+     json = False

+     if args is not None and args.json:

+         json = True

+ 

+     objectclass_elems = schema.get_objectclasses(json=json)

+     attributetype_elems = schema.get_attributetypes(json=json)

+     matchingrule_elems = schema.get_matchingrules(json=json)

+ 

+     if json:

+         print(dump_json({'type': 'schema',

+                          'objectclasses': objectclass_elems,

+                          'attributetypes': attributetype_elems,

+                          'matchingrules': matchingrule_elems}))

+     else:

+         separator_line = "".join(["-" for _ in range(50)])

+         print("Objectclasses:\n", separator_line)

+         for oc in objectclass_elems:

+             print(oc)

+         print("AttributeTypes:\n", separator_line)

+         for at in attributetype_elems:

+             print(at)

+         print("MathingRules:\n", separator_line)

+         for mr in matchingrule_elems:

+             print(mr)

+ 

+ 

  def list_attributetypes(inst, basedn, log, args):

      log = log.getChild('list_attributetypes')

      schema = Schema(inst)
@@ -281,6 +310,8 @@ 

      schema_parser = subparsers.add_parser('schema', help='Query and manipulate schema')

  

      schema_subcommands = schema_parser.add_subparsers(help='schema')

+     schema_list_parser = schema_subcommands.add_parser('list', help='List all schema objects on this system')

+     schema_list_parser.set_defaults(func=list_all)

  

      attributetypes_parser = schema_subcommands.add_parser('attributetypes', help='Work with attribute types on this system')

      attributetypes_subcommands = attributetypes_parser.add_subparsers(help='schema')

file modified
+6 -6
@@ -355,7 +355,7 @@ 

          """Returns a list of ldap.schema.models.ObjectClass objects for all

          objectClasses supported by this instance.

  

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

          """

  
@@ -365,7 +365,7 @@ 

          """Returns a list of ldap.schema.models.AttributeType objects for all

          attributeTypes supported by this instance.

  

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

          """

  
@@ -374,7 +374,7 @@ 

      def get_matchingrules(self, json=False):

          """Return a list of the server defined matching rules

  

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

          """

  
@@ -386,7 +386,7 @@ 

  

          :param mr_name: the name of the matching rule you want to query.

          :type mr_name: str

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

  

          :returns: MatchingRule or None
@@ -408,7 +408,7 @@ 

  

          :param objectclassname: The name of the objectClass you want to query.

          :type objectclassname: str

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

  

          :returns: ObjectClass or None
@@ -432,7 +432,7 @@ 

  

          :param attributetypename: The name of the attributeType you want to query

          :type attributetypename: str

-         :param json: dump the result into JSON format

+         :param json: return the result in JSON format

          :type json: bool

  

          :returns: (AttributeType, Must, May) or None

Description: Get all the schema in one search, then the UI loads it
once, and parse out attrs, oc's, and mr's.
Add 'dsconf schema list' command for that.
Reset x-origin field in 'clear_form()' funcitons.
Set 'View' header for the view modal form.

https://pagure.io/389-ds-base/issue/50061

Reviewed by: ?

ACK, I do see a noticeable improvement in loading time: less than 3 seconds

rebased onto 5dc9101df7a77dc6ab05029ab75db6d7f8e0ced5

5 years ago

rebased onto 55ec4ef

5 years ago

Pull-Request has been merged by spichugi

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3127

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago