4

I heard that there are improvements in Web 8 with the performance of rendering lists in the GUI.

I've written a GUI Extension that adds a new column for the filename. The sourcecode is online here: https://github.com/rcurlette/filename-in-gui

Is it possible to improve the performance of this code that uses a reader object to access the item XML and append a new filename attribute to it? Code is below and whole class is here: https://github.com/rcurlette/filename-in-gui/blob/master/AddFilename.cs

/// <summary>
/// Idea here is to re-create the XmlTextReader Node and this accounts for 50% of the code.
/// Original code borrowed from http://www.sdltridionworld.com/community/2011_extensions/parentchangenotifier.aspx
/// Thanks for the work from Serguei Martchenko - would not be possible without his example!
/// </summary>
/// <param name="xReader"></param>
/// <param name="context"></param>
/// <returns></returns>
private XmlTextReader PreprocessListItems(XmlTextReader xReader, PipelineContext context)
{
    TextWriter sWriter = new StringWriter();
    XmlTextWriter xWriter = new XmlTextWriter(sWriter);
    string attrName = "pageFilename";
    string attrValue = "";  // set this to 'fieldValue', for example, to debug and prove it is working

    xReader.MoveToContent();

    while (!xReader.EOF)
    {
        switch (xReader.NodeType)
        {
            case XmlNodeType.Element:
                xWriter.WriteStartElement(xReader.Prefix, xReader.LocalName, xReader.NamespaceURI);

                // add all attributes back  -- always START with this to NOT break the GUI
                xWriter.WriteAttributes(xReader, false);

                try
                {
                    // add my custom attribute
                    if (IsValidItem(xReader))
                    {
                        string id = xReader.GetAttribute("ID");  // URI
                        string title = xReader.GetAttribute("Title");  // Title
                        string type = xReader.GetAttribute("Type"); //Type

                        if (type == "64")
                        {
                            PageData pageData = (PageData)client.Read(id, new ReadOptions());
                            attrValue = pageData.FileName;
                        }

                        // add new metadata field attribute
                        xWriter.WriteAttributeString(attrName, attrValue);
                        xReader.MoveToElement();
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("EXCEPTION " + ex.Message + ex.ToString() + ex.StackTrace);
                }

                if (xReader.IsEmptyElement)
                {
                    xWriter.WriteEndElement();
                }
                break;

            case XmlNodeType.EndElement:
                xWriter.WriteEndElement();
                break;
            case XmlNodeType.CDATA:
                // Copy CDATA node  <![CDATA[]]>
                xWriter.WriteCData(xReader.Value);
                break;
            case XmlNodeType.Comment:
                // Copy comment node <!-- -->
                xWriter.WriteComment(xReader.Value);
                break;
            case XmlNodeType.DocumentType:
                // Copy XML documenttype
                xWriter.WriteDocType(xReader.Name, null, null, null);
                break;
            case XmlNodeType.EntityReference:
                xWriter.WriteEntityRef(xReader.Name);
                break;
            case XmlNodeType.ProcessingInstruction:
                xWriter.WriteProcessingInstruction(xReader.Name, xReader.Value);
                break;
            case XmlNodeType.SignificantWhitespace:
                xWriter.WriteWhitespace(xReader.Value);
                break;
            case XmlNodeType.Text:
                xWriter.WriteString(xReader.Value);
                break;
            case XmlNodeType.Whitespace:
                xWriter.WriteWhitespace(xReader.Value);
                break;
        }
        xReader.Read();
    };

    xWriter.Flush();

    xReader = new XmlTextReader(new StringReader(sWriter.ToString()));
    xReader.MoveToContent();
    //-> Write XML of tcm:Item out...
    //   This is where the attribute in the config file is matched.  
    Trace.Write(sWriter.ToString() + Environment.NewLine);
    return xReader;
}
  • 1
    One of the biggest changes done is that you can use Event System code for this instead of DataExtenders (you still need to fiddle with the config to add the column) meaning that the data collection piece runs in the CM core instead of on "something invoked by the UI". There should be an event triggered when lists get loaded. – Nuno Linhares Jun 2 '16 at 13:54
  • 1
    Oh, and you can do a Bulk Load of items which results in a single database call for all the items instead of iterating through all of them – Nuno Linhares Jun 2 '16 at 13:55
  • Sounds great. I was unable to find a code sample in the live documentation and cannot hack my way through the API. Maybe if someone can post a code sample here using the event system that would be a huge help. – robrtc Jun 2 '16 at 22:43
2

As Nuno mentioned in his comment above, this can now be done via the Event System to improve performance.

You'll need to subscribe to the following 'Processed' event on the OrganizationalItem: EventSystem.Subscribe<OrganizationalItem, GetListEventArgs<OrganizationalItemItemsFilter>>(CUSTOMMETHOD, EventPhases.Processed);

Further details, including code samples for this approach, can be found on the Extension example: adding a new column to a list view page in the SDL Web 8.5 online documentation.

Previous versions of the documentation (e.g. SDL Web 8 and before) included this example, but did it using the mechanism you describe above, so you should be able to compare these.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.