Copied to clipboard

Flag this post as spam?

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


  • Harm-Jan Abbing 62 posts 102 karma points
    Jul 28, 2011 @ 21:47
    Harm-Jan Abbing
    0

    Voting with email check. Best way to do this.

    Hey guys,

    First some backgroundinfo.

    I made a form with which a user can grade something, fill out some details and submit. Then contour sends a confirmation email with link containing a unique code. When the user clicks the link he is send to a page with a usercontrol that validates the code, checks if the email address has not been submitted yet and, if everything's cool, approves the record.

    Now, after almost a thousand votes the validationpage takes ages to complete. I'm wondering if i went about this the right way. The usercontrol loops through all records and checks if the record is not approved yet and if the emailaddress matches the submitted emailaddress. It is very possible that my code is far from optimal (just started developing in .Net) but is this the right way of doing it? Maby i should move the email check to the votingpage, like in a custom fieldtype. But then i would still need to loop through all records..

    I would very much like to see some decent sample code for looping approved records and checking the email address. (I'm not using linq, should i?)

    Any tips are much appreciated!

    Kind regards,
    Harm

  • Comment author was deleted

    Aug 01, 2011 @ 10:33

    Hi Harm,

    Sounds like a good way of doing it but you can probably improve the code. Do you mind sharing the snippet?

     

  • Harm-Jan Abbing 62 posts 102 karma points
    Aug 01, 2011 @ 10:48
    Harm-Jan Abbing
    0

    Thanks for the comment Tim, here's the code for the confirmation control.

    Like i said, i've just started developing in .Net so there's probably a lot that can be improved but the important thing is that it's way to slow.

    namespace ConfirmControl
    {
        public partial class ConfirmControl : System.Web.UI.UserControl
        {
            public string bevestigdMsg { get; set; }       
            public string alBevestigdMsg { get; set; }
            public string ongeldigMsg { get; set; }

            protected void Page_Load(object sender, EventArgs e)
            {
                String qsRecord = Request.QueryString["rid"];
                String qsSecret = Request.QueryString["cid"];
                Int16 emailCount = 0;

                if (IsGUID(qsRecord) && !String.IsNullOrEmpty(qsSecret) && !String.IsNullOrEmpty(qsRecord))
                {
                    Umbraco.Forms.Data.Storage.RecordStorage storage = new Umbraco.Forms.Data.Storage.RecordStorage();
                    Umbraco.Forms.Core.Record record = storage.GetRecord(new Guid(qsRecord));

                    if (storage.GetAllRecords(record.Form).Count > 0)
                    {
                        IEnumerable rList = storage.GetAllRecords(record.Form);
                        foreach (Record rec in rList)
                        {
                            if (rec.State.ToString() == "Approved" && String.Equals(rec.GetRecordField("Emailadres:").Values[0].ToString(), record.GetRecordField("Emailadres:").Values[0].ToString(), StringComparison.CurrentCultureIgnoreCase))
                                emailCount += 1;
                        }
                    }

                    RecordService rs = new RecordService(record);

                    String strSecret = FormsAuthentication.HashPasswordForStoringInConfigFile(topsecretproperty, System.Web.Configuration.FormsAuthPasswordFormat.MD5.ToString());
                    Boolean checkSecret = String.Equals(qsSecret, strSecret, StringComparison.CurrentCultureIgnoreCase);

                    if (checkSecret)
                    {
                        if (emailCount == 0)
                        {
                            MsgLabel.Text = bevestigdMsg;
                            rs.Approve();
                        }
                        else
                            MsgLabel.Text = alBevestigdMsg;
                    }
                    else
                        MsgLabel.Text = ongeldigMsg;

                    rs.Dispose();
                }
                else
                    MsgLabel.Text = ongeldigMsg;
            }

            public static bool IsGUID(string expression)
            {
                if (expression != null)
                {
                    Regex guidRegEx = new Regex(@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");

                    return guidRegEx.IsMatch(expression);
                }
                return false;
            }
        }
    }
  • Harm-Jan Abbing 62 posts 102 karma points
    Aug 04, 2011 @ 16:57
    Harm-Jan Abbing
    0

    Narrowed down to this code it's still way too slow:

    Umbraco.Forms.Data.Storage.RecordStorage storage = new Umbraco.Forms.Data.Storage.RecordStorage();
    List<Umbraco.Forms.Core.Record> recordList = storage.GetAllRecords(new Guid("[formguid]"));

    foreach (Record rec in recordList)
    {
    if (rec.State.ToString() == "Approved")
    doStuff(rec.GetRecordField("Emailadres:").ValuesAsString());
    }
  • Harm-Jan Abbing 62 posts 102 karma points
    Aug 22, 2011 @ 11:15
    Harm-Jan Abbing
    0

    Sorry to bump this but i am still looking for a way to loop and check a couple thousand contour records the right way.
    Is GetAllRecords the right method for this? I can't specify a pageId because voting takes place on different pages.

    Any tips are much appreciated.

  • Mark 122 posts 255 karma points
    Dec 20, 2013 @ 12:07
    Mark
    0

    Hi There,

    I know this is a couple of years after the party, but did you ever find a quicker way of looping through the records?

    I'm finding myself in need of looping through 50k+ records. I'm only needing to do it once every now and then as I'm using Lucene to index the results for lightning fast searching, but to rebuild the index is stupidly slow.. It's hammerring SQL..

    Mark

Please Sign in or register to post replies

Write your reply to:

Draft