inherit
243783
0
Dec 19, 2020 2:48:04 GMT -8
Alenet
60
April 2017
alenet
|
Post by Alenet on May 22, 2017 3:21:58 GMT -8
I implemented a download manager (counter) plugin. As you can see here (http://tesreloaded.com/thread/2/package), there is a list of packages you can download. Every package has its counter. The data is saved into a post key using a json stringyfied object (1 post can have multiple download link).
The problem is that the download counter is wrong (it is less than the real downloads). This is generated by the fact that i started to have more than 10000 views per day and over 1000 downloads per day (i see them on google analytics) and more than one user clicks "at the same time" on the download link. I made some tests and i saw that there is a concurrency on saving data due to the time of the json call made by several users at the same time. Every time you click the link, i read the key, increment it (+1) and save the key. But if 3 people click on the link "at the same time" (anyway very closed to), the counter is incremented only once due to the time of the read/write sequence.
How could i manage and solve this? I think it is impossible to client-side or is there a workaround?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on May 22, 2017 6:38:54 GMT -8
Because you allow multiple downloads per post, and store data about those downloads in the post key together. Then no, you can't have accurate counters, as the data will likely become stale for the user depending on download activity.
If it was one download per post, and all you were storing was the counter. Then you could use the increment method, as that doesn't increment the value based on stale data on the page. It actually does this server side, and returns it back. Meaning it will be 100% accurate.
|
|
inherit
243783
0
Dec 19, 2020 2:48:04 GMT -8
Alenet
60
April 2017
alenet
|
Post by Alenet on May 22, 2017 7:07:22 GMT -8
Yeah. I supposed that but i would maintain the downloads in a single view.
I could provide to place a download for each post but i should heavily javascript the thread to "rebuild" the view like now. Like for example some plugins do (Member Gallery for example use a post for each link image but change the view of the thread to make it an image gallery).
Could you provide a quick example of the increment method?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on May 22, 2017 7:24:11 GMT -8
var post_id = 1 // post id var key_obj = pb.plugin.key("your_key"); var method = (!key_obj.get(post_id))? "set" : "increment";
key_obj[method]({
object_id: post_id, value: 1 // defaults to 1 anyway, but need it here for the "set"
});
console.log(key_obj.get(post_id)); If the key doesn't contain a value to begin with, then it will be undefined. To solve this, we have to do a set on the key to initiate the starting value. Then additional calls make use of the increment method. If you are still confused at this, just test increment with an empty key to see the response.
|
|
inherit
243783
0
Dec 19, 2020 2:48:04 GMT -8
Alenet
60
April 2017
alenet
|
Post by Alenet on May 22, 2017 9:59:54 GMT -8
No problems about the initialization. I know that. I format the key for each use with this method:
formatkey: function (key, id) { if (key == undefined) { key = {}; } else { key = JSON.parse(key.value); } if (key[id] == undefined) key[id] = 0; return key; }
If undefined i initialize it because in my case i store a map. Your example is clear.
Now i have to script a plugin to make a board (or thread, i evaluate) into a sort of download section.
|
|
inherit
243783
0
Dec 19, 2020 2:48:04 GMT -8
Alenet
60
April 2017
alenet
|
Post by Alenet on May 26, 2017 6:18:27 GMT -8
www.tesreloaded.com/thread/2/packageNow it works well. Obviously i cannot know if the file has been really downloaded but it is enough. The plugin needs the board/s where to work on, then it formats the page layout and provides the support for HTML in posts. Then for each post, it places the download and its counter. No settings are needed. Everything is auto-detected using jqueries. Thank you!
|
|