Existing methods:
Start time [@start_dt] End time [@end_dt]
other conditions []
Total query data: [XXXX]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20
Disadvantages:
If you have 1000 data, each page shows 50, you need to display 20 page connections.
The query needs to query a total amount of data first:
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt}}). Count ()
Re-query detail data:
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt}}). Skip (@pageno-1). Limit (50)
When you view the number of pages more and more, skip (@pageno-1) is larger, performance is worse.
Optimization method: 1 (previously proposed)
In order to reduce invalid query data return, the Application page, @start_dt, @end_dt two values default range of 1 weeks, or half a month, reduce the number of queries once.
This modification, just do not modify the page layout, simple to modify.
Previously, in the absence of default, the user is one months, a few months of the situation, the following query waiting for a few 10 seconds ...
More disgusting is that each page defaults to one months of the query range, the page opened on the automatic query run results. Make the page very slow to open, the user experience is very bad.
(Open the page does not automatically query, so that users choose to query the range, and then click and then query, relatively good many)
Optimization Method: 2
page does not display all the data page connection, also does not show the total query data, the query only inquires the number of each page 50 +1
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt}}). Limit (51)
If there are 51 records,
The page appears below the table (next page). Click on the next page to look at the following data
Total query data: [XXXX]
[Next Page]
Advantages: Returns a small amount of data
Disadvantages:
Click on [Next], if you can pinpoint to a record, such as:
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt},_id:{$gte: @no_51_id}}). Limit (51)
_ID is greater than or equal to the _id value of the 51st record that you just queried.
If you cannot pinpoint to a row, such as only time field value {date: {$gte: @no_51_date}}, there may be an inaccurate problem.
Optimization method: 3
This method can be said to be the above two kinds of compromise. Check only 201 records for the first time
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt}}). Limit (201)
If the total number of returns is less than this number, then the Display page does not show [more], if there are 201 items, display
Total query data: [MB]
1 2 3 4 more
This method is very clever to tell the user that only 201 records are checked at a time, need more, can also be viewed.
It also reduces the amount of data returned to 201.
The second query is as follows:
Db.coll_name.find ({date:{$gt: @start_dt, $lte: @end_dt}}). Skip (201)
You only need to record a variable value: (A few clicks [more] to record how much data to skip.) In fact, users will not always page, turn more pages, but also reduce the scope of the query
Advantages: The user experience is good, the existing changes are not large, the amount of data returned is small
Disadvantage: But if more pages are turned, performance will be worse.