Currently, the logic which is used to count the number of views is placed in the block code. It is causing 2 issues: Views not getting counted if block isn't placed and practically no caching for the counter block. Event subscribers would be a better way to execute the counting logic.

Comments

koosvdkolk created an issue. See original summary.

sumanthkumarc’s picture

Yes. Since if you see the code(.module file), all the queries are written in hook_block_view. Hence this gets called only when block is rendered i guess. Even i was surprised by this.

lomasr’s picture

Hi,

I tested the same and found the opposite.

Created a video.

Thanks

Lomas

gaurav.kapoor’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Moving to 8.x-1.x so that it is debugged and fixed in D 8/9 release as well.

gaurav.kapoor’s picture

Component: Documentation » Code

I didn't see any issues in views getting logged but the logic of counting a view and other statistics should be moved to an event subscriber.

gaurav.kapoor’s picture

Title: Only working if block is present? » Modify the counting logic.

Currently, the logic which is used to count the number of views is placed in the block code. It is causing 2 issues: Views not getting counted if block isn't placed and practically no caching for the counter block. Event subscribers would be a better way to execute the counting logic.

gaurav.kapoor’s picture

Issue summary: View changes

  • gaurav.kapoor authored 54601e1 on 8.x-1.x
    Issue #2558459 by lomasr, gaurav.kapoor: Modify the counting logic
    
gaurav.kapoor’s picture

I have moved the logic to count views to an event subscriber, will keep this issue open till all the other improvement related issues are closed.

gaurav.kapoor’s picture

Status: Active » Needs review
gaurav.kapoor’s picture

Status: Needs review » Fixed

Closing this one for now as most of the coding practice improvement related issues have been fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.