Resolved Broken gained monthly reader

nightshade.valentine

Well-known member
Joined
Dec 22, 2020
Messages
52
Points
58
Tested on: Chrome, iPhone, Safari

Problem:
When I click on the gained monthly reader it keeps loading forever .

Manual Fix:
You need to switch to year and back to month in order for the number to fix themselves.

Screenshot 2021-02-14 at 15.16.53.png
 

nightshade.valentine

Well-known member
Joined
Dec 22, 2020
Messages
52
Points
58
Are you still having this problem? I can't seem to recreate this bug.
Yes . It happens right just moment . The year is broken somehow, maybe that is why?
 

Attachments

  • F0D4ABAE-5960-4968-8773-2CE5B03BC30A.png
    F0D4ABAE-5960-4968-8773-2CE5B03BC30A.png
    522.3 KB · Views: 73

Tony

Moderator
Staff member
Joined
Dec 21, 2018
Messages
704
Points
133
Yes . It happens right just moment . The year is broken somehow, maybe that is why?

I fixed the year problem. Can you check if it's still bugging out for you? I can't seem the recreate the bug which causes the stats to not load. If you still have that problem, do you know how to check your browser's console for errors?

I still have it sometimes.

Which bug? The bug that doesn't load or the year problem?
 

nightshade.valentine

Well-known member
Joined
Dec 22, 2020
Messages
52
Points
58
I fixed the year problem. Can you check if it's still bugging out for you? I can't seem the recreate the bug which causes the stats to not load. If you still have that problem, do you know how to check your browser's console for errors?



Which bug? The bug that doesn't load or the year problem?
Hey Tony in the console error there is only two warnings (but I doubt that they are related). I posted a screenshot for you anyways.Happy to do more debugging
 

Attachments

  • Screenshot 2021-02-19 at 12.09.15.png
    Screenshot 2021-02-19 at 12.09.15.png
    499.1 KB · Views: 69

nightshade.valentine

Well-known member
Joined
Dec 22, 2020
Messages
52
Points
58
Ok, so I definitely could not see an interesting JS error in the console. but here are my observations.
  • You will only be able to re-generate this bug, by going to stats from Create -> click Stats button of one of the series. and then it will open the Stats page directly as the first load
  • The auto-selected Stats will be "Valid Reads" (charts colored in blue) , if you click on the Gained then it says "loading chart"
  • Click on other tabs e.g Glossary, Table of Contents.. and go back to the statistics tab, the "Gained" will be auto-selected and the numbers will show correctly!


Minor note: If you click on "Valid Reads" after navigating to other tabs, the chart will show in red instead of blue, but it doesn't matter.

If you'd like to debug, here is the link (or simply choose any edit series with the tab stats as a parameter) : https://www.scribblehub.com/editseries/212992/?tab=stats
 
Last edited:

DarkGodEM

Book Editor
Joined
Sep 12, 2020
Messages
311
Points
103
It has always happened for me since I joined the platform.
Click the Month button, change to Year and back to month.
Then It'll load (It still flickers back to Year occasionally though... But works)
 

Tony

Moderator
Staff member
Joined
Dec 21, 2018
Messages
704
Points
133
The doesn't load bug, though I haven't seen it recently.

Hey Tony in the console error there is only two warnings (but I doubt that they are related). I posted a screenshot for you anyways.Happy to do more debugging

Ok, so I definitely could not see an interesting JS error in the console. but here are my observations.
  • You will only be able to re-generate this bug, by going to stats from Create -> click Stats button of one of the series. and then it will open the Stats page directly as the first load
  • The auto-selected Stats will be "Valid Reads" (charts colored in blue) , if you click on the Gained then it says "loading chart"
  • Click on other tabs e.g Glossary, Table of Contents.. and go back to the statistics tab, the "Gained" will be auto-selected and the numbers will show correctly!


Minor note: If you click on "Valid Reads" after navigating to other tabs, the chart will show in red instead of blue, but it doesn't matter.

If you'd like to debug, here is the link (or simply choose any edit series with the tab stats as a parameter) : https://www.scribblehub.com/editseries/212992/?tab=stats

It has always happened for me since I joined the platform.
Click the Month button, change to Year and back to month.
Then It'll load (It still flickers back to Year occasionally though... But works)

I'm not sure what the problem is at this moment but let me look into it.
 

Reisinling

Well-known member
Joined
Feb 5, 2021
Messages
357
Points
63
@Tony I found 1 more thign related to the bug- it seems that when you use the workaround the old points are still active, just invisible. What I mean is that the flicker between yearly and monthly gained readers is due to hovering over a data point from the other period (that is if I'm in year tab, and move mouse over the space where monthly readers gained would be displayed, it switches to year, and then switches back If i do the same but for yearly tab datapoint, but name in the dropdown stays the same)
 

Mihou

Firefly—
Joined
Mar 18, 2020
Messages
297
Points
103
I'm not sure what the problem is at this moment but let me look into it.
The admin-ajax.php is not being called on the initial click, this could be the issue.
1615146219927.png


The expected function should be that jquery would be calling admin-ajax with the proper POST parameters, for example, this:
1615146271690.png

After a bit of investigation, I have found that openTab(e, s) in fact doesn't actually call rd_gained(o), not a single mention of it and the only method that actually calls rd_gained(o) is the switch tag on the HTML side which is why the graph loads when switching from Year to Month. This could (and maybe is) the issue.

This code is rewritten a bit so I can understand it easier, original is the one below.
JavaScript:
// The original code.
function openTab(e, s) {
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month"), $(".tab_sh_rcontent").hide(), $(".tab_sh_rlinks").removeClass("active"), document.getElementById(s).style.display = "block", $(e.currentTarget).addClass("active")
}

// A little bit cleaner look of the original code.
function openTab(e, s) {
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month"); // It only calls for vr_gained which is valid reads.
    $(".tab_sh_rcontent").hide();
    $(".tab_sh_rlinks").removeClass("active");
    document.getElementById(s).style.display = "block";
    $(e.currentTarget).addClass("active");
}

// An updated expected solution is shown in the next post.
// And also explains the issue in a bit more detail.

To add: #rg_loaded's value is always false unless you change option to Year (which would then trigger rd_gained("year") and changes the #rg_loaded to yes which makes me a bit sure that the issue really lies on openTab.

I wonder if you forgot about the function for it? (or I could be wrong, all in all, this is my speculation after a ten minute debug.
(unrelated but noticed, $.post(...) makes ajax posts easier and also jQuery.parseJson(...) is deprecated for JSON.parse(...) )
 
Last edited:

Mihou

Firefly—
Joined
Mar 18, 2020
Messages
297
Points
103
(This post is separated from the one at the top because the post would be too large, I want to keep them as organized as possible).

Since I couldn't replicate the scenario with official means, I decided to replicate it in a different manner, here is what I have in essence.

Think of execute(s) is opentab(e, s) which would determine which method to use depending on the condition, in the current version of the script, the function only calls for vr_gained, the code won't trigger rd_gained(o) because there is no condition for it as seen on the second picture.
1615185868369.png

1615186076229.png


A simple solution to this issue is to simply add a check and trigger if s is tab_r_gained which is the trigger word for reader gains.
1615186256757.png


And after changing up the code, it woud look like this.
JavaScript:
// A little change to make it into a one-liner.
function openTab(e, s) {
    // This calls for either vr_gained or rd_gained depending on the conditions.
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month") || "tab_r_gained" == s && "yes" != $("#rg_loaded").val() && rd_gained("month");
    $(".tab_sh_rcontent").hide();
    $(".tab_sh_rlinks").removeClass("active");
    document.getElementById(s).style.display = "block";
    $(e.currentTarget).addClass("active");
}

which would then allow these two results.
1615186300093.png

1615186330244.png


Well, that's all I have after investigating for a while. I hope this helps out in fixing this bug (which has been here for literal months since reader gains function was added *cough*, I normally wouldn't delve much into this if it didn't make me curious over what was causing this issue).
 
Last edited:

Tony

Moderator
Staff member
Joined
Dec 21, 2018
Messages
704
Points
133
Ok, so I definitely could not see an interesting JS error in the console. but here are my observations.
  • You will only be able to re-generate this bug, by going to stats from Create -> click Stats button of one of the series. and then it will open the Stats page directly as the first load
  • The auto-selected Stats will be "Valid Reads" (charts colored in blue) , if you click on the Gained then it says "loading chart"
  • Click on other tabs e.g Glossary, Table of Contents.. and go back to the statistics tab, the "Gained" will be auto-selected and the numbers will show correctly!


Minor note: If you click on "Valid Reads" after navigating to other tabs, the chart will show in red instead of blue, but it doesn't matter.

If you'd like to debug, here is the link (or simply choose any edit series with the tab stats as a parameter) : https://www.scribblehub.com/editseries/212992/?tab=stats

It has always happened for me since I joined the platform.
Click the Month button, change to Year and back to month.
Then It'll load (It still flickers back to Year occasionally though... But works)

@Tony I found 1 more thign related to the bug- it seems that when you use the workaround the old points are still active, just invisible. What I mean is that the flicker between yearly and monthly gained readers is due to hovering over a data point from the other period (that is if I'm in year tab, and move mouse over the space where monthly readers gained would be displayed, it switches to year, and then switches back If i do the same but for yearly tab datapoint, but name in the dropdown stays the same)

The admin-ajax.php is not being called on the initial click, this could be the issue.View attachment 6682

The expected function should be that jquery would be calling admin-ajax with the proper POST parameters, for example, this:View attachment 6683
After a bit of investigation, I have found that openTab(e, s) in fact doesn't actually call rd_gained(o), not a single mention of it and the only method that actually calls rd_gained(o) is the switch tag on the HTML side which is why the graph loads when switching from Year to Month. This could (and maybe is) the issue.

This code is rewritten a bit so I can understand it easier, original is the one below.
JavaScript:
// The original code.
function openTab(e, s) {
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month"), $(".tab_sh_rcontent").hide(), $(".tab_sh_rlinks").removeClass("active"), document.getElementById(s).style.display = "block", $(e.currentTarget).addClass("active")
}

// A little bit cleaner look of the original code.
function openTab(e, s) {
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month"); // It only calls for vr_gained which is valid reads.
    $(".tab_sh_rcontent").hide();
    $(".tab_sh_rlinks").removeClass("active");
    document.getElementById(s).style.display = "block";
    $(e.currentTarget).addClass("active");
}

// An updated expected solution is shown in the next post.
// And also explains the issue in a bit more detail.

To add: #rg_loaded's value is always false unless you change option to Year (which would then trigger rd_gained("year") and changes the #rg_loaded to yes which makes me a bit sure that the issue really lies on openTab.

I wonder if you forgot about the function for it? (or I could be wrong, all in all, this is my speculation after a ten minute debug.
(unrelated but noticed, $.post(...) makes ajax posts easier and also jQuery.parseJson(...) is deprecated for JSON.parse(...) )

Sorry about the delay! It's fixed.

(This post is separated from the one at the top because the post would be too large, I want to keep them as organized as possible).

Since I couldn't replicate the scenario with official means, I decided to replicate it in a different manner, here is what I have in essence.

Think of execute(s) is opentab(e, s) which would determine which method to use depending on the condition, in the current version of the script, the function only calls for vr_gained, the code won't trigger rd_gained(o) because there is no condition for it as seen on the second picture.
View attachment 6688
View attachment 6689

A simple solution to this issue is to simply add a check and trigger if s is tab_r_gained which is the trigger word for reader gains.
View attachment 6690

And after changing up the code, it woud look like this.
JavaScript:
// A little change to make it into a one-liner.
function openTab(e, s) {
    // This calls for either vr_gained or rd_gained depending on the conditions.
    "tab_r_validreads" == s && "yes" != $("#vr_loaded").val() && vr_gained("month") || "tab_r_gained" == s && "yes" != $("#rg_loaded").val() && rd_gained("month");
    $(".tab_sh_rcontent").hide();
    $(".tab_sh_rlinks").removeClass("active");
    document.getElementById(s).style.display = "block";
    $(e.currentTarget).addClass("active");
}

which would then allow these two results.
View attachment 6691
View attachment 6692

Well, that's all I have after investigating for a while. I hope this helps out in fixing this bug (which has been here for literal months since reader gains function was added *cough*, I normally wouldn't delve much into this if it didn't make me curious over what was causing this issue).

Thanks for taking the time to look into it! I edited it a bit differently though
 

Mihou

Firefly—
Joined
Mar 18, 2020
Messages
297
Points
103
It seems like you made it open by default, not complaining since it's fixed fufufu. :blobtaco:
 

Mihou

Firefly—
Joined
Mar 18, 2020
Messages
297
Points
103
1615350268614.png

Yeah, I can see that which is also fine since it decreases the time it takes to load the reader statistics, thanks for the hardwork! Thread can now be marked as resolved.
 
Top