Use average speed paging method in ASP to increase paging speed

zhaozj2021-02-16  53

Unsettime

First, the applicable range unit is mainly suitable for the ASP Access Application of the Sort Method of Article System, News System.

Second, there are many people who have used some article systems or news systems that know that the general article system or news system, when classified paging, usually after reading the database, then the data is satisfied, then according to the request page No., by positioning operation, pointing to a piece of data, and starting a number of data behind this data as a page. This paging method, the principle is simple, but the problem is that every time you need to read the sort of the condition in the database, if there are two thousand data, this is ok, if there are 20,000 pieces? Display, this will occupy a lot of memory, waste a lot of server resources. Of course, if there is conditional, you can use the SQL database, so you can do more, and use a little stored procedure to all solve it. However, many friends are still in use access database, so there is no way. Of course, there are some programs to generate html, just like a lot of download sites, have you ever thought that there is any problem? If I add a record in the background, I have to regenerate all the pactions in this category to HTML, this is sure, think about it, this efficiency is very poor. The average sport method is to solve the patch of a large amount of data in the Access database. It has the advantages of HTML paging and traditional ADO pagination. First, fast, less resources, whether you are the first page or hundreds of pages, the program speed is the same. And when data is added, you don't have to regenerate all pactions. Let me introduce the principle.

Third, the patch principle database has an article table, a class table, we don't consider whether an unlimited classification is still two-level classification, this is not related to us. [Article] ID Int Id IDENTITY (1) NOT NULL, CLASSID INT Default 0, Title Varchar (100), Addtime DateTime [Class] ID INT IDENTITY (1, 1) Not Null, ClassName Varchar (20)

1, generate a page If there is a line of data in the class table is 1, classname is "ASP classification", let's take out all the cop-all ClassID = 1 data in all Article, then arrange the AddTime ascending, this with ordinary ADO The same is true, but we have to do some processing below. We dynamically generate a table in the database, named [Page_1], 1 is the corresponding classname for "ASP Classification" ID Auto number. [Page_1] Pagenum Int, PageStr Text

We first generate a STR every 20 data, each STR is actually displayed, the list of these 20 databases, then the number XXX is compiled for this STR, if it is 0-19 records, then xxx is 001, if it is 20- 39, XXX is 002 and push it in this class. Add the STR and its number to Page_1. We assume the biggest 84 here

Everyone will definitely think that data is not always 19 (20 data should be MOD 19), of course, we have to handle zero heads, these zero should be the latest data (we press AddTime). We re-dynamically create a table, [aritcle_1] [article_1] id int identity (1, 1) not null, artid int, classid int default 0, title varchar (100), addtime datetime add more zero-headed data to this table in. 2, the display definition of the data is the number of records of [Page_1]

We are divided into two situations (1) if Article_1 does not record (no zero data), the first page is 84, 83. The second page is 82, 81, the third page is 80, 79 ... Northern page: PageCount- (2) * N-2), PageCount- (2 * n-2) -1

(2) If Article_1 has record (zero-headed data) first page, call Article_1 data, 84 Page II, 83, 82 ... The n-page is: pagecount- (2 * n-3), PageCount- (2 * N-3) -1

Explanation: 84, 83, etc. These numbers are in Page_1, you correspond to the STR number XXX

It may be understood that the principle of the average pages method is actually the principle of average pages, and the page is directly spliced ​​when paging. This is more resource that directly calls data from the database from the database every time the paging is time. At the same time, it can be explained that you can do not build the PAGE_1 table, and save these STR to HTML, then read the HTML page when paging.

3, data adding to the traditional HTML paging, after adding new data, regenerate all HTML paging once, in average unit, there is no such thing. We have set up only 20 records for each small page, and only 19 records are only saved in the article_1 table. We newly added a record, then add this record to Article_1, if the data in Article_1 has exceeded 19, then generate a STR in the data, plus the number and saved in [Page_1], of course, If you use to generate HTML, you can generate an HTML directly. If the data in Article_1 has not exceeded 19, then don't worry it.

Fourth, the average patch method and the traditional paging comparison I use a database of 2,000 data for testing, under the XP system, under the hardware conditions of the P3 1G, 256M memory, with average speed paging method in average speed at 50ms, positive Negative no more than 10ms, with ordinary ADO pagination, speed at 85ms, positive and negative between 20-35ms, can be used to use average speed paging method, are good at speed and stability.

Of course, for a small database, such advantages may not be obvious, or may be faster than the ADO pagination, but if the average speed of the average page method is a normal ADO pagination method if the paging of 20,000 data is Half.

Of course, the average patching method also has its own shortcomings, such as the high program complexity is higher than the traditional paging, and the performance is not as good as ADO when the database is less.

Fifth, the last point of explanation: This article mainly introduces a principle of average pages, I spent a night using procedures, it is feasible. But I mainly read the STR to generate HTML, which is a bit different from the database stored in this article, but the principle is the same. If you have a condition to use the SQL database, then I suggest you use the stored procedure to implement the speed of patch.

If you have any questions, you can communicate with me http://www.showc.com/

转载请注明原文地址:https://www.9cbs.com/read-24041.html

New Post(0)