Home  >  Article  >  CMS Tutorial  >  Discuz theme views implementation principle and solution to non-updating

Discuz theme views implementation principle and solution to non-updating

咔咔
咔咔Original
2020-04-30 15:23:042367browse

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