Copied to clipboard

Flag this post as spam?

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


  • David Armitage 505 posts 2073 karma points
    Mar 20, 2016 @ 10:47
    David Armitage
    0

    Umbraco - Update multiple node programmatically

    Hi,

    I have a scenario where I really need to optimize the speed of updating umbraco.

    Scenario...

    I am sending email alerts to 100ds / 1000ds of nodes.

    1. First I get each node awaiting an email alert

      • No problem I can return a list pretty quick and only hit the database once.
    2. I then generate the email template and send out each email

      • No problems here. Takes a while but sending emails do.
    3. I then update each notes LastSentDate so I know not to send them the email alert again.

      • This is the problem. Individually updating each node is very time consuming and at the moment takes multiple hits to the database.

    I am thinking there is a better way to update all these nodes in one go. My questions are.....

    1. Does the Umbraco API have a method which does exactly this. I am hoping I can just compile a list of nodeIds and fire this at Umbraco to update in one go.

    2. Failing this my plan B would be to manually update all the records directly to the database. Is there a function in the Umbraco API that allows me to pass in SQL to run an update. If so what is this and is there anything I need to do after the database update to make sure the XML is inline with the database (re-publish or something)?

    Thanks

    David

  • Rhys Hamilton 20 posts 89 karma points
    Mar 21, 2016 @ 11:19
    Rhys Hamilton
    0

    May I ask, why are the nodes awaiting an alert email?

    Does this alert email only apply to newly generated nodes, or are these alert emails sent out frequently to all nodes?

  • David Armitage 505 posts 2073 karma points
    Mar 23, 2016 @ 02:13
    David Armitage
    0

    Hi,

    No this is not just for new nodes. I have a collection of contacts (nodes) which I will batch send notifications emails to.

    It's not a massive problem but I would like to update all nodes as sent in one update rather than hitting the database for each node.

    for example possibly passing a list of nodes into the save and publish method or something on the same lines.

    contentService.SaveAndPublishWithStatus(List);

    Kind Regards

    David

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 23, 2016 @ 07:55
    Dave Woestenborghs
    1

    Hi David,

    What is the trigger for sending the e-mail.

    We have also done something sending bulk mails and the mails get a lot of content for the nodes.

    We how ever created at a mail queue table. So when our trigger fires for the node we get all the data needed to send the e-mail (mailto, mailfrom, body,..) and create a record in the mail queue table.

    We than have a scheduled task that reads out this database and starts sending the mails.

    Dave

  • Rhys Hamilton 20 posts 89 karma points
    Mar 24, 2016 @ 14:24
    Rhys Hamilton
    0

    There seems to be multiple solutions to your problem.

    You mentioned how you update each nodes 'LastSentDate', so that you know not to send another alert email.

    Personally, I would remove this property completely, and instead opt to send a confirmation e-mail or provide some kind of alert which tells you that you have sent alert emails to all of the contacts.

    You could include specific details about this email, it is entirely up to yourself.

    Whilst this might not be entirely robust, it will certainly reduce the database hits and still inform you that all nodes have been alerted.

    Alternatively, you could nest the contacts within another node which contains a 'LastSentDate' property. You could send an alert email to all of your contacts, then update this single property ONLY when all emails have been sent.

Please Sign in or register to post replies

Write your reply to:

Draft