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.
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.
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:
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:
Type, count and Id are gotten through razor on Current Umbraco page, since that is where relevant data is. Action is called with ajax.
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
This is a huge Umbraco antipattern. Please, please, please don't.
https://our.umbraco.org/Documentation/Reference/Common-Pitfalls/#using-umbraco-content-items-for-volatile-data
Alright I won't. Any Ideas where to and how store data?
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/
is working on a reply...