Discuz theme views implementation principle and solution to non-updating
Main content of this article:
Solution to the problem that the Discuz topic views do not change or change together with the number of reply posts
If you are a novice discuz developer, you can view the article from the beginning
If you are a webmaster, just read the summary at the bottom of the article
More articles are in the column: Discuz column
Questions Restore
This page is the theme page
The red box above is the theme pageviews using $_G[forum_thread][views]
All the replies below use $_G[forum_thread][replies]
for the number of replies. However, the number of views will not increase when we refresh the page, but when the topic replies to a post, the number of views will not increase. The volume will increase
# Then let’s test it and add a new reply, and we will find that it is indeed the case! But the problem is not that simple, please continue to read below
Troubleshooting steps
Step one: We need to confirm the number of views and replies Is the volume of these two fields
The second step: We need to trace the principle of the increase in pageviews
Then let’s troubleshoot the first step Question: Open the database dictionary to view the pre_forum_thread table, then we will confirm that the variables we use in the source code are correct
Traceability implementation The principle
In line 986 of the code, we have solved our first problem, which is why the data of page views and replies are the same. This is because here Made a judgment. If the number of reply posts is greater than the number of topic views, the number of views will be equal to the number of replies
Then continue to look for the code to update the topic views: at 1054# There is a viewthread_updateviews method in the ## line. According to the literal meaning, we can all understand what this method does, and the theme updates the number of views.
The steps to execute this code
- First check whether the optimization theme views optimization function is turned on in the background
- Then determine the value of
addviews in the global variable
- If the value is less than 100, the data will be updated to
pre_forum_threadaddviews This table
- If the value of
addviews is greater than 100, the views of this topic will be cleared, and then the data will be stored in pre_forum_thread Views field of the topic table
- This is the basic implementation process
- In the above, we found that the views will not be stored directly into the topic table. The advantage of this is to prevent frequent updates to the topic table and prevent the table from being locked.
preventrefresh value controls whether it is turned on or not. To optimize the number of topic views, just configure it according to Kaka.
But as a developer, the implementation of a function point must be traced back to the source code. Only in this way can we continuously improve ourselves.The above is the detailed content of Discuz theme views implementation principle and solution to non-updating. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function