Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Giovanni Sidoel 94 posts 233 karma points
    Jul 09, 2015 @ 17:08
    Giovanni Sidoel
    0

    Umbraco forms library slow in back-end

    Hey guys,

    I have a custom section in the backoffice in which I get all records from a form and display them. This however, is painfully slow even with as low as 10 records.

    But if you just view the records in Contour's own section in the back-office, that just works lightning fast.

    Is there another way of retrieving these records that's faster I am missing?

    DynamicRecordList records = Library.GetRecordsFromForm(eventID);

            // GET THE ORIGNAL LIST OF RECORDS
            IEnumerable<DynamicRecord> recordsItems = records.Items.Where(x => x.State.ToString() == "Approved");
    

    and then further down I loop through them

    foreach (var item in recordsItems)
                {
                    RecordStorage storage = new RecordStorage();
                    Record record = storage.GetRecord(new Guid(item.Id));
                var recordFields = record.RecordFields; //.OrderBy(r => r.Value.Field.PageIndex).ThenBy(r => r.Value.Field.FieldsetIndex).ThenBy(r => r.Value.Field.SortOrder);
    
                string naam = "";
                string email = "";
                string evenementnaam = "";
                string evenementcode = "";
                foreach (var field in recordFields)
                {
                    //FULLNAME
                    if (field.Value.Field.Caption.ToLower() == "achternaam" || field.Value.Field.Caption.ToLower() == "tussenvoegsel" || field.Value.Field.Caption.ToLower() == "voornaam")
                    {
                        naam += field.Value.ValuesAsString() + " ";
                    }
                    if (field.Value.Field.Caption.ToLower() == "e-mailadres")
                        email = field.Value.ValuesAsString();
                    if (field.Value.Field.Caption.ToLower() == "evenementnaam")
                        evenementnaam = field.Value.ValuesAsString();
                    if (field.Value.Field.Caption.ToLower() == "evenementcode")
                        evenementcode = field.Value.ValuesAsString();
                }
    

    }

  • Comment author was deleted

    Jul 09, 2015 @ 17:45

    Yeah the records viewer works with the tranformed records xml, maybe this code snippet can get you started

            private void ReturnRecords(Guid id, DateTime date, FormState state, int startIndex, int lenght, Sorting sortOrder) {
            FormStorage fs = new FormStorage();
            Umbraco.Forms.Core.Form f = fs.GetForm(id);
            fs.Dispose();
    
            List<FormState> states = new List<FormState>();
            states.Add(state);
    
            RecordsViewer rv = new RecordsViewer();
            XmlNode x = rv.GetPagedXmlRecords(startIndex, lenght, -1, sortOrder, f, states, date, new XmlDocument());
            rv.Dispose();
    
            Dictionary<string, object> settings = new Dictionary<string, object>();
            settings.Add("form", f.ToXml(new XmlDocument()).CreateNavigator().Select("."));
    
            //if (umbraco.GlobalSettings.ApplicationTrustLevel > AspNetHostingPermissionLevel.Medium)
            //{
                Response.Write(Regex.Replace(Data.XsltHelper.TransformXML(x, HttpContext.Current.Server.MapPath("../xslt/datatables_json.xslt"), settings), "<.*?>", string.Empty));
            //}
            //else
            //{
            //    Response.Write(Regex.Replace(Data.XsltHelper.TransformXML(x, HttpContext.Current.Server.MapPath("../xslt/DataTables_json_medtrust.xslt"), settings), "<.*?>", string.Empty));
            //}
        }
    
  • Giovanni Sidoel 94 posts 233 karma points
    Jul 16, 2015 @ 20:09
    Giovanni Sidoel
    0

    Thanks for the tip Tim. That got me started in the right direction. If anybody has to do this, keep in mind that you'll be getting back json with this snippet.

  • Comment author was deleted

    Jul 17, 2015 @ 08:21

    Great, glad it was helpful!

  • Brendan Rokebrand 7 posts 131 karma points
    Sep 13, 2016 @ 19:46
    Brendan Rokebrand
    0

    Hi Giovanni, Tim

    I'm doing a similar thing where I need to find records that were submitted from a particular pageID, I'm having trouble finding the recordsViewer(), I'm using umbraco 7.3.8, any help would be appreciated

    Regards Brendan

  • Matthew Kirschner 323 posts 611 karma points
    Jul 21, 2017 @ 19:16
    Matthew Kirschner
    0

    The RecordsViewer class does not seem to exist in my Forms 6.0.2 installation. Has this been replaced with something else?

  • Jan Bengtsson 64 posts 107 karma points
    Dec 04, 2017 @ 12:45
    Jan Bengtsson
    0

    I'm also looking for a light-weight entry-fetcher since Library.GetRecordsFromForm is way too slow and RecordsViewer seem to be obsolete. Umbraco version: 7.5.3, Forms version: 4.3.2.

  • Jan Bengtsson 64 posts 107 karma points
    Dec 08, 2017 @ 14:14
    Jan Bengtsson
    0

    If anyone else is struggling with this, here's the solution I came up with. It reduced the time for fetching 700 form entries from 15 seconds to 1!

    Short summary:

    1. Use the GetAllRecords method and set its second parameter (includeFields) to false.
    2. Get the content of custom fields by deserializing the record's RecordData property.

    Here's the code:

    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Web.Mvc;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Data.Storage;
    using Umbraco.Web;
    using Umbraco.Web.Mvc;
    
    /***************************************************************************/
    
     using (var formStorage = new FormStorage())
    {
        using (var recordStorage = new RecordStorage())
        {
            // Get form by guid
            var form = formStorage.GetForm(formGuid));
    
            // Get all form records. Note the second, includeFields, parameter of the GetAllRecords method.
            List<Record> recordList = recordStorage
                .GetAllRecords(form, false)
                .OrderBy(x => x.Created)
                .ToList();
    
            // Iterate over the records
            foreach (Record record in recordList)
            {
                // Get content of current entry's all custom fields
                string jsonData = record.RecordData.ToString();
    
                // Deserialize the json objects (guid/value) to a Dictionary's key/value pair
                Dictionary<string, string> fieldsDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonData);
    
                // Get state
                string approved = record.State.ToString();
    
                // Get first name (custom field)
                string firstName = fieldsDictionary[fieldGuidFirstName];
    
                //*********************************************************************************
                // The part where the custom fields content is assigned to a custom object, which
                // in turn is added to a list, is removed here for readability reasons.
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft