View count decreased with increase (+) statement

Hello, i’m trying to count the views when someone clicks on a sound.

That’s my blocks and view count increases well but i found out something that doesn’t makes any sense.
I went to sleep and saved the previous views made, when i woke up i checked how many views i got and i found out that some sound’s views decreased. How is that possible to happen?

Hello,
Personally I’m not familiar with spreadsheet but what I think happened is that:
If multiple users are using your app at the same time, then:
User 1: Receive value (example 100) then + 1
User 2: Receive value after user 1 added 1 so 101 + 1
User 3: Also receive value but before the 1 was added by user 1 it still have 100 and add 1.
Which make the highest view 101 while 103 people had view the element.

A good explanation is that Youtube video.

1 Like

Hi @nickxpanos!

It could be a possible that the global indextoviews to have changed between when you fetch the value to when you’re storing it back after incrementing.

Consider the following scenario:
A user plays song number 20, which has views count to be around 290.
The player completes and the method to fetch the views count is executed (in Player Completed event).
But before the Spreadsheet.Got Cell event is called(it might have been delayed due to slow internet etc.), the user clicks on another song, say song 22, which changes the global indextoviews to 22.

Now, when the Spreadsheet. Got Cell is triggered eventually, it increments the value to 291, but instead of storing it in index 20, it now stores that in index 22 (because the global variable was changed).

I suspect that is what has happened here.

1 Like

I just tested that scenario and you are 100% correct!!!

My thoughts now are, how can i fix that? :thinking: :thinking:

Add what I call an input pipeline. Add the indextoviews values to a list, and have your view increment method work down the list. The spreadsheet would be called by this method, which would prevent the user from breaking the order.

So if you got indices 20, 22, 28 in rapid succession, the incrementor method would first fetch the value for the first index, when the value is received it’d do the view increment and fetch for the second index, and so on.
Note: the incrementor must be called:
a. If the pipeline is empty, and an index is added.
b. At the end of the GotCell method, if the pipeline is not empty.

1 Like

Okay that blew my mind up!
I can understand how pipeline works but can’t figure out how i can implement that on blocks or i’m thinking so complicated.
If you have spare time can you show me how i can do that?

I really appreciate your suggestion!

I’ll be free in a couple hours. I’ll try to cook up a demonstration for you then. :slight_smile:

Edit: Windows has been updating since the morning. It’s late in the afternoon, and I haven’t been able to get any work done. :frowning:

1 Like

5 posts were split to a new topic: Short Discussion About Linux

@nickxpanos Sorry for the long wait!

1 Like

Thank you so much! I’m sure with my basic knowledge about lists i’ll never be able to do this.

I have to study more :frowning:

You’ll learn with practice. :slight_smile:

P.S.: So does my method work for you?

*Edit: No
Only if the user change song rapidly it mixes up the views but i fixed that with a timer (.5 sec delay between changes)

1 Like

@Kanishka_Developer i tested that with 2 devices at the same time but it mixes up the views
It gets the view count from cell number 22 (for example) and put it in the cell number 23

That’s very strange, since the pipeline is unchanged from the GET to the SET. Let’s see if someone else can point out what’s wrong. :sweat_smile:

ezgif.com-video-to-gif

Only one user changes a sound. Especially if the user uses mobile data and not WiFi the mix up error exists.

1 Like