search
HomeCMS TutorialDiscuzDiscuz 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

Discuz theme views implementation principle and solution to non-updating

# 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

Discuz theme views implementation principle and solution to non-updating

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

Discuz theme views implementation principle and solution to non-updating

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

Discuz theme views implementation principle and solution to non-updating

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.

Discuz theme views implementation principle and solution to non-updating

Summary

At this point I I understand everything I need to understand. The reason why the number of topic views does not increase is actually controlled by the background, because you can see in the first line of the above code that the

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

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

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function