Copied to clipboard

Flag this post as spam?

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


  • Anamarija Horvat 25 posts 140 karma points
    Feb 23, 2017 @ 14:50
    Anamarija Horvat
    1

    Making counters (Setting property value using content service)

    In my project I have 2 counters on certain events (Video started, Video ended). Counters are initially set in content then on event I am calling action that takes current value from content, increments it and saves and publishes. Time to do that takes between 1.5 and 2 seconds which is an issue because if action is called again before first call ended it'll take the old value meaning it will increment once instead twice. (Or even once instead many times depending how many times action was called). My question is there a way to somehow put actions in que, or set up counting some other faster way instead using propery editors. Only thing that matters is that my users have to somewhere get the counter values, and that counter value most be "true". This is my action:

     public ActionResult SetCounter(string type, int count, int id)
            {
                var contentService = Services.ContentService;
                var content = contentService.GetById(id);
                content.SetValue(type, count);
                contentService.SaveAndPublishWithStatus(content);
    
                return Json(true);
            }
    

    Type, count and Id are gotten through razor on Current Umbraco page, since that is where relevant data is. Action is called with ajax.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Feb 23, 2017 @ 15:00
    Nik
    2

    Hi Anamarija,

    My first advise is don't do this. It is highly advisable not to use properties on content nodes for counter style values as each save and publish creates a new version. And, as you've seen it can be slow.

    I would advise using a custom data object, or the relationship service to create/update something like this. I don't have an exact example to hand (sorry) but I felt it important to flag the issue with having it as a content property item.

    Nik

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2017 @ 20:50
  • Anamarija Horvat 25 posts 140 karma points
    Feb 24, 2017 @ 10:24
    Anamarija Horvat
    0

    Alright I won't. Any Ideas where to and how store data?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 24, 2017 @ 12:33
    Sebastiaan Janssen
    101

    In this blog post I have an example of how to store things like this in a custom table, I'm sure it could easily be expanded upon with a few more columns:

    https://cultiv.nl/blog/using-umbraco-migrations-to-deploy-changes/

Please Sign in or register to post replies

Write your reply to:

Draft