Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

2.1 View count won't increament.

chanhchanh OngETC.com - CMS Researcher ✭✭

Vanilla 2.1, Vanilla Statistics is enable.
Does anyone has this problem where the view count won't increment?

Thanks

«134567

Comments

  • peregrineperegrine MVP
    edited May 2014

    I used to have the same problem you describe with previous vanilla versions so I wrote a plugin.

    but miraculously for me (the view count) does INDEED increment for me on 2.1 on a localhost without vanilla statistics and I don't even have to use... http://vanillaforums.org/addon/incrementview-plugin

    however, several of my clients use it :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    That's work.
    Thanks

  • LincLinc Detroit Admin

    View count will not increment if you have a Javascript error on the discussion view page or have removed the AfterBody event or Foot asset from your theme.

  • LincLinc Detroit Admin
    edited May 2014

    Also, you may need to set Vanilla.Views.Denormalize = TRUE in your config for it to count every pageview. Otherwise it will attempt to count in 10s to save on database writes. Disregard.

  • @Linc said:
    Also, you may need to set Vanilla.Views.Denormalize = TRUE in your config for it to count every pageview. Otherwise it will attempt to count in 10s to save on database writes.

    Don't you mean FALSE?

    grep is your friend.

  • peregrineperegrine MVP
    edited May 2014

    @Linc said:
    Also, you may need to set Vanilla.Views.Denormalize = TRUE in your config for it to count every pageview. Otherwise it will attempt to count in 10s to save on database writes.

    I was wondering about that. if a person hit your site frequently (not an attack) or you had alot of non-malicious bots reading discussions and you had the view count incremented on every view. Could this cause performance problems. I guess the short answer : it depends how frequently.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Detroit Admin

    @x00 said:
    Don't you mean FALSE?

    I was wrong anyway, disregard. Old data. We fixed it for 2.1 to not need that.

  • LincLinc Detroit Admin

    @peregrine said:
    Could this cause performance problems. I guess the short answer : it depends how frequently.

    Yes. For larger sites, you will want to enable caching anyway and then set Vanilla.Views.Denormalize = TRUE to only count in 10s; the intermediate counts are made only in cache to save on database writes.

  • chanhchanh OngETC.com - CMS Researcher ✭✭
    edited May 2014

    @Linc said:
    View count will not increment if you have a Javascript error on the discussion view page or have removed the AfterBody event or Foot asset from your theme.

    None of these apply to my situation but the view count just won't increment until I install the plugin suggested. I disable it so you can see for yourself.

    I use VBS3 theme so does that cause the problem?

    http://uhostetc.com

    Thanks

  • LincLinc Detroit Admin
    edited May 2014

    I bet this is a MySQL strict mode issue. Check out DiscussionModel line 1837 (end of the AddView method).

  • I'm having the same issue. (Ver. 2.1 using Bittersweet theme) I installed it about a week ago, the statistics show almost 2,000 page views but each discussion shows 1 view. Not a huge deal but would be nice. If I can't get it to work I might just edit the theme to not display it at all.

  • peregrineperegrine MVP
    edited May 2014

    @hdjohnston

    If I can't get it to work I might just edit the theme to not display it at all.

    well aside from the plugin to increment, assuming you can't get it to work some other way.

    you could add these to conf/locale.php

    to not display views.

    $Definition['%s view html'] = '';
    $Definition['%s views html'] = '';

    and possibly these

    $Definition['%s view'] = '';
    $Definition['%s viewsl'] = '';

    http://vanillaforums.org/discussion/26597/tutorial-how-to-change-wording-how-to-change-text-how-to-change-language-how-to-change-locale#latest

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    @hdjohnston Try the statsbox plugin, that fired up my views ...

  • chanhchanh OngETC.com - CMS Researcher ✭✭
    edited May 2014

    My site is on a share host so I don't believe they turn on strict mode. Here is the Mysql mode on my share host.

    mysql> select @@sql_mode;
    +------------+
    | @@sql_mode |
    +------------+
    | |
    +------------+
    1 row in set (0.00 sec)


    mysql> select @@GLOBAL.sql_mode;
    +-------------------+
    | @@GLOBAL.sql_mode |
    +-------------------+
    | |
    +-------------------+
    1 row in set (0.00 sec)

    I think there might be a bug in 2.1b2 and 2.1 regarding view count increment. I notice this when I upgrade from 2.0 to 2.1b2 but didn't pay attention about it until last few days.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I even do a fresh 2.1 install to check this out and the view count is not increment either.

  • LincLinc Detroit Admin
    edited May 2014

    Well, I'd be keenly interested if anyone can narrow this down to an issue report. peregrine's counterexample of it working correctly makes me reluctant to go on a wild goose chase since I may not be capable of reproducing.

  • peregrineperegrine MVP
    edited May 2014

    only difference with mine and everyone else's is this: my experience - localhost and vanillastatistics not enabled. apc caching not enabled nor is any other caching.

    could be that is the difference when people have problems. I don't have a live non-localhost forum to test it on.

    too bad others can't chime in. bittersweet theme no other view incrementing plugins do views works with vanillastatistics enabled on a live site that is not in mysql strict mode - yes or no! its not that hard for other people (besides chanh, linc, and hdjohnston) to maybe lend a hand in reporting back.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • hgtonighthgtonight ∞ · New Moderator

    I have never had an issue with counts incrementing on any of my installs. Localhosts included.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • peregrineperegrine MVP
    edited May 2014

    @chanh

    here is how to debug. it is all temporary - so you will need to undo when you have finished debugging.

    there may be something wrong with
    Gdn::Cache()->ActiveEnabled()

    add this to your config.php

    $Configuration['Garden']['Errors']['LogEnabled'] = TRUE;
    $Configuration['Garden']['Errors']['LogFile'] = 'log/DebugLog';

    if your forum is in the "vanilla" directory.

    create a folder called log (give it permissions 777)

    e.g.

    vanilla/log

    if your forum is in forum the folder would be in forum

    e.g. forum/log

    all of your debug messages will go to a file called DebugLog

    which you can view.

    then go into

    /applications/vanilla/models/discussionmodel.php

    temporarily replace around line 1837

        public function AddView($DiscussionID) {
          $IncrementBy = 0;
          if (C('Vanilla.Views.Denormalize', FALSE) && Gdn::Cache()->ActiveEnabled()) {
             $WritebackLimit = C('Vanilla.Views.DenormalizeWriteback', 10);
             $CacheKey = sprintf(DiscussionModel::CACHE_DISCUSSIONVIEWS, $DiscussionID);
    
             // Increment. If not success, create key.
             $Views = Gdn::Cache()->Increment($CacheKey);
                // added this one line
             LogMessage(__FILE__,__LINE__,'Object','Method',"my views are $Views"); 
             if ($Views === Gdn_Cache::CACHEOP_FAILURE)
                Gdn::Cache()->Store($CacheKey, 1);
    
             // Every X views, writeback to Discussions
             if (($Views % $WritebackLimit) == 0) {     
               $IncrementBy = floor($Views / $WritebackLimit) * $WritebackLimit;
                Gdn::Cache()->Decrement($CacheKey, $IncrementBy);
             }
          } else {
             $IncrementBy = 1;
          }
          // added these three lines
          LogMessage(__FILE__,__LINE__,'Object','Method',"myincrement is: $IncrementBy"); 
          $IncrementBy = 2;
          LogMessage(__FILE__,__LINE__,'Object','Method',"mynew increment is:$IncrementBy"); 
    
           if ($IncrementBy) {
             $this->SQL
                ->Update('Discussion')
                ->Set('CountViews', "CountViews + {$IncrementBy}", FALSE)
                ->Where('DiscussionID', $DiscussionID)
                ->Put();
          }
    
        }
    

    you should then see in the DebugLog file

    something like this. and you will increment discussions by 2.

    06 May 2014 - 01:51:05: [Garden] /var/www/vanilla/applications/vanilla/models/class.discussionmodel.php, 1837, Object.Method(), myincrement is: 1
    06 May 2014 - 01:51:05: [Garden] /var/www/vanilla/applications/vanilla/models/class.discussionmodel.php, 1839, Object.Method(), mynew increment is:2
    

    make the changes and report back your results.

    do it EXACTLY as my instructions state. and it will provide some information.

    read the above three times before you do anything.

    after you make the above changes.

    go to the discussions page.

    click on a discussion and the view count should increment by 2.

    you will see the before and after values of IncrementBy -

    myincrement is: 0 then that will give you a clue.
    mynewincrement is: 2

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited May 2014

    I think if

    Vanilla.Views.Denormalize is set to TRUE in your config.php

    IncrementBy will always be 0.

    because

    $Views % $WritebackLimit is always equal to 1


    if (C('Vanilla.Views.Denormalize', FALSE) && Gdn::Cache()->ActiveEnabled()) {

    elvaluates to TRUE

    then

    $Views = Gdn::Cache()->Increment($CacheKey);

    viewis always evaluates to 1

    if (($Views % $WritebackLimit) == 0) {

    always evaluates to 1

    and $IncrementBy never gets set and is always 0

    and incrementBy is never set to 1 because it can't be reached unless Vanilla.Views.Denormalize is FALSE or Gdn::Cache()->ActiveEnabled() is false.

    never set here:
    $IncrementBy = 1;

    therefore the database never updates.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.