Page skipping query method and device, storage medium and processor
By determining the node containing the target page in the cached data on the front-end page and using the Elasticsearch API to load the data, the problem of not being able to randomly flip through pages in Elasticsearch data queries was solved, improving query speed and reducing the pressure on the back-end service.
Patent Information
- Application Number
- CN202411536665.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2044-10-31
AI Technical Summary
Existing Elasticsearch data queries do not support pagination from back to front, and existing methods suffer from issues such as non-real-time response times, memory overflow, or only allowing pagination from back to front.
By obtaining the target page for querying, determining the node where the target page is located based on the data size and node size of each page, querying the cached data on the front-end page, and using the ElasticSearch API to load data, random access and cache management are achieved.
It improved query speed, reduced the pressure on backend services, maintained the stateless architecture of backend services, and minimized the impact on user experience and page performance while meeting requirements.
Smart Images

Figure CN119520611B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a page skipping query method, a page skipping query device, a machine-readable storage medium, a computer program product, and a processor. Background Technology
[0002] In the field of data management, Elasticsearch is often used as a data search engine to assist in structured queries. Elasticsearch's pagination query primarily offers the following three methods: 1. Shallow pagination using `from + size`: Its advantage is support for random page navigation; its disadvantage is limitation by Elasticsearch's `max_result_window` parameter, preventing unlimited page navigation and slowing down as you go further. 2. Scroll pagination: Its advantage is support for full page traversal, not limited by `max_result_window`; its disadvantage is non-real-time response time, and requiring sufficient memory to preserve context, otherwise it is prone to memory overflow. 3. SearchAfter pagination: Its advantage is not limited by `max_result_window`, allowing unlimited page navigation; its disadvantage is that it can only navigate backwards and does not support random page navigation.
[0003] Therefore, when using Elasticsearch as a data search engine for data querying, there is a problem that you can only flip through pages from the beginning to the end, and you cannot flip through pages from the end to the beginning. Summary of the Invention
[0004] The purpose of this application is to provide a page-skipping query method, a page-skipping query device, a machine-readable storage medium, a computer program product, and a processor. This page-skipping query method allows for random access to previously visited pages, thus improving query speed.
[0005] To achieve the above objectives, the first aspect of this application provides a page skipping query method, including:
[0006] Retrieve the target page for the query;
[0007] Based on the target page, the preset data size per page, and the node size, the node where the target page is located is determined;
[0008] Based on the node where the target page is located, a query is performed in the cached data of the front-end page to obtain the query result. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, each node is used to store different blocks of data in the back-end data.
[0009] In this embodiment of the application, the step of querying the cached data of the front-end page based on the node where the target page is located to obtain the query result includes:
[0010] A1: Determine whether the node containing the target page is in the cached data of the front-end page;
[0011] A2: If it is determined that the node where the target page is located is in the cached data of the front-end page, a query is performed in the cached data of the front-end page based on the node where the target page is located to obtain the query result;
[0012] A3: If it is determined that the node where the target page is located is not in the cached data of the front-end page, cache the block data corresponding to the next node in the back-end data into the cached data of the front-end page to update the cached data of the front-end page, and then jump to execute A1.
[0013] In this embodiment of the application, the step of caching the block data corresponding to the next node in the backend data to the cache data of the frontend page, so as to update the cache data of the frontend page, and jumping to execute A1 includes:
[0014] The number of nodes to be scrolled forward is calculated based on the node number of the target page and the node number of the current node.
[0015] Determine whether the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes;
[0016] If it is determined that the number of forward-crossing nodes exceeds the maximum allowed number of cached nodes, it is then determined whether the number of forward-crossing nodes exceeds the maximum number of forward-traversing nodes.
[0017] If it is determined that the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, the block data corresponding to the next node in the backend data is cached in the cache data of the frontend page to update the cache data of the frontend page, and then jump to execute A1.
[0018] In this embodiment of the application, caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page includes:
[0019] Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0020] Based on the number of valid cache nodes and the node size, the ElasticSearch API is called to perform a query and obtain the returned data;
[0021] The returned data is cached as the block data corresponding to the next node in the cache data of the front-end page, so as to update the cache data of the front-end page.
[0022] In this embodiment of the application, the step of querying the cached data of the front-end page based on the node where the target page is located to obtain the query result includes:
[0023] Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0024] Based on the node where the target page is located, the target page, the data size per page, and the node size, a first parameter is calculated. The first parameter is used to represent the number of data items that need to be skipped after reaching the node where the target page is located.
[0025] Based on the number of valid cache nodes and the first parameter, the ElasticSearch API is called to perform a query and obtain the query results.
[0026] In this embodiment of the application, the calculation of the first parameter based on the node where the target page is located, the target page being queried, the data size per page, and the node size includes:
[0027] Substituting the node containing the target page, the target page, the data size per page, and the node size into the preset formula for calculating the query range, we obtain the first parameter. The preset formula for calculating the query range is as follows:
[0028] Size=gotoPage*pageSize-(gotoNode-1)*nodeSize,
[0029] Where gotoPage is the target page for the query, pageSize is the size of each page, gotoNode is the node where the target page is located, nodeSize is the size of the node, and Size is the first parameter.
[0030] In this embodiment of the application, it also includes:
[0031] Determine whether the cache of the front-end page has expired;
[0032] If the cache of the front-end page is determined to be invalid, the cached data shall be cleared.
[0033] In this embodiment of the application, it also includes:
[0034] Determine whether the current query conditions have changed;
[0035] If it is determined whether the current query conditions have changed, the cache is initialized, and based on the changed current query conditions, the corresponding block data in the backend data is loaded into the frontend page cache.
[0036] In this embodiment of the application, determining the node containing the target page based on the target page, the preset data size per page, and the node size includes:
[0037] Substituting the target page, the preset page size, and the node size into a pre-defined node calculation formula, the node containing the target page is obtained. The pre-defined node calculation formula is as follows:
[0038] gotoNodeIdx=Ceiling(gotoPage*pageSize / nodeSize),
[0039] Where gotoNodeIdx is the node where the target page is located, gotoPage is the target page for the query, pageSize is the size of the data per page, and nodeSize is the size of the node.
[0040] A second aspect of this application provides a page skipping query device, the page skipping query device comprising:
[0041] The retrieval module is used to retrieve the target page for the query.
[0042] The determination module is used to determine the node where the target page is located based on the target page, the preset data size per page, and the node size.
[0043] The query module is used to query the cached data of the front-end page based on the node where the target page is located, and obtain the query results. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, and each node is used to store different blocks of data in the back-end data.
[0044] A third aspect of this application provides a processor configured to execute the above-described page skipping query method.
[0045] A fourth aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the page skipping query method described above.
[0046] The fifth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described page skipping query method.
[0047] The above technical solution involves obtaining the target page for querying; determining the node containing the target page based on the target page, the preset data size per page, and the node size; and querying the cached data of the front-end page based on the node containing the target page to obtain the query results. The cached data of the front-end page is obtained by loading corresponding blocks of data from the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, each of which stores different blocks of data from the back-end data. By determining the node containing the target page, the nearest node to the target page can be identified first, and the query can then start from the node containing the target page, achieving page-jumping queries. Random access can also be achieved for pages that have been visited, improving the query speed. By caching key node information about the current query conditions through the front-end page, the stateless architecture of the back-end service is maintained. The back-end does not need to cache node information for each session condition, reducing the pressure on the back-end service and not affecting its scalability. At the same time, the front-end caching method, based on calculations, will not involve a large amount of data, minimizing the impact on user experience and page performance while meeting requirements.
[0048] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0049] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings:
[0050] Figure 1 This illustration schematically shows an application environment diagram of the page skipping query method according to an embodiment of this application;
[0051] Figure 2 The schematic diagram illustrates a flowchart of a page skipping query method according to an embodiment of this application;
[0052] Figure 3 This illustration schematically shows a detailed process diagram of page skipping query according to an embodiment of this application;
[0053] Figure 4 This schematic diagram illustrates a structural block diagram of a page-skipping query device according to an embodiment of the present application;
[0054] Figure 5 The diagram illustrates the internal structure of a computer device according to an embodiment of this application.
[0055] Explanation of reference numerals in the attached figures
[0056] 102-Terminal; 104-Server; 410-Acquisition Module; 420-Determination Module; 430-Query Module; A01-Processor; A02-Network Interface; A03-Internal Memory; A04-Display Screen; A05-Input Device; A06-Non-Volatile Storage Medium; B01-Operating System; B02-Computer Program. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0058] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of the components in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0059] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0060] The acquisition, transmission, storage, use, and processing of data in this application comply with relevant national laws and regulations. Furthermore, it should be noted that existing industry solutions such as software, components, and models may be mentioned in the embodiments of this application. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0061] The page skipping query method provided in this application can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network. By determining the node where the target page is located, the node closest to the target page can be identified first. Then, during the query, the query starts from the node where the target page is located, enabling page skipping. Random access to previously visited pages is also possible, improving query speed. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. Server 104 can be a standalone server or a server cluster consisting of multiple servers.
[0062] Figure 2 A schematic diagram illustrating a page-skipping query method according to an embodiment of this application is shown. Figure 2 As shown, in one embodiment of this application, a page skipping query method is provided. This embodiment mainly applies this method to the above-mentioned... Figure 1 Taking terminal 102 (or server 104) as an example, the following steps are included:
[0063] Step S210: Obtain the target page for the query;
[0064] In this embodiment, the target page for querying can be obtained by inputting the target page on the front-end page; the target page refers to the page to be queried. User interface actions can be used to determine if an interface event is a query event.
[0065] Step S220: Based on the target page, the preset data size per page, and the node size, determine the node where the target page is located;
[0066] In this embodiment, the node size refers to the amount of data that a node can store, which can be preset. The size of each page of data can be known in advance. Based on the target page to be queried, the preset size of each page of data, and the node size, the node where the target page is located can be calculated.
[0067] In some embodiments, determining the node containing the target page based on the target page, a preset page size, and a node size includes: substituting the target page, the preset page size, and the node size into a preset node calculation formula to obtain the node containing the target page. The preset node calculation formula is:
[0068] gotoNodeIdx=Ceiling(gotoPage*pageSize / nodeSize),
[0069] Where gotoNodeIdx is the node where the target page is located, gotoPage is the target page for the query, pageSize is the size of the data per page, and nodeSize is the size of the node.
[0070] In this embodiment, Ceiling refers to the floor function, which rounds the parameter up. Specifically, after calculating `gotoPage*pageSize / nodeSize`, it rounds up to obtain the node number of the target page's node, thus determining the node containing the target page. The node containing the target page is the node whose value is closest to the target page.
[0071] By using the floor function, the node number of the nearest node to the target page can be quickly and accurately calculated, thus determining the node where the target page is located. Once the node of the target page is determined, the approximate location of the data can be pinpointed, facilitating the rapid retrieval of query results.
[0072] Step S230: Based on the node where the target page is located, query the cached data of the front-end page to obtain the query result. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, and each node is used to store different block data in the back-end data.
[0073] In this embodiment, the cached data on the front-end page is data pre-loaded into the front-end page cache. This data can be stored in the front-end page cache after the last page jump query, provided the query conditions haven't changed. Alternatively, it can be obtained by caching the corresponding chunks of data on the front-end page based on the current query conditions. Specifically, this can be obtained through a page load event. When a page load event occurs, the cache node configuration is first obtained, including: the maximum number of cache nodes, which can be represented as `maxCachedNodeSize`; and the maximum number of nodes to traverse forward, which can be represented as `maxPosGapSizeByNode`. Then, the cache can be initialized based on `maxCachedNodeSize`, thereby initializing the cached data. It should be noted that the cached data can be stored in the form of an array or other data structures; this embodiment does not limit this. When the cached data is stored in the form of a cache array, the cache array can be initialized based on the cache node configuration. The cached data includes multiple nodes, with each chunk of data stored in its respective node. Each node can be numbered to obtain its node number. After determining the node containing the target page, a query can be performed in the front-end page cache data to find the corresponding data and obtain the query result.
[0074] In some embodiments, to improve query speed, before performing a query, it can be determined whether the node containing the target page is in the cached data of the front-end page. That is, the query based on the node containing the target page in the cached data of the front-end page to obtain the query result includes the following steps:
[0075] Step A1: Determine whether the node containing the target page is in the cached data of the front-end page;
[0076] In this embodiment, the above-mentioned judgment may be to determine whether the node where the target page is located is a valid cache node. A valid cache node refers to a node in the front-end page's cache that caches chunked data. After determining the cached data of the front-end page, the valid cache nodes can be determined. For example, in a specific implementation, the nodes can be numbered starting from 0, and the current number of valid cache nodes can be obtained, denoted as validCount. The node number where the target page is located is gotoNodeIdx. Then, in the judgment, it may be to determine whether gotoNodeIdx-1 exceeds the current number of valid cache nodes validCount.
[0077] Step A2: If it is determined that the node where the target page is located is in the cached data of the front-end page, a query is performed in the cached data of the front-end page based on the node where the target page is located to obtain the query result;
[0078] In this embodiment, if the node containing the target page is in the cached data of the front-end page, then the query can be performed within the cached data of the front-end page. For example, in the example above, if gotoNodeIdx-1 does not exceed the current valid cached node count (validCount), it means that the key node information required for this query is already in the cache and can be queried within the cached data of the front-end page.
[0079] In some embodiments, the step of querying the cached data of the front-end page based on the node where the target page is located to obtain the query results includes:
[0080] First, determine the number of valid cache nodes in the cached data of the front-end page, where the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0081] In this embodiment, the node numbers in the cached data can be numbered sequentially from smallest to largest, and the number of effective cached nodes is the largest node number of the effective cached nodes in the cached data of the front-end page.
[0082] Then, based on the node where the target page is located, the target page being queried, the data size per page, and the node size, a first parameter is calculated. The first parameter is used to represent the number of data entries that need to be skipped after reaching the node where the target page is located.
[0083] In this embodiment, the first parameter can be used as the size parameter when calling the ElasticSearch query API.
[0084] The calculation of the first parameter based on the node where the target page is located, the target page being queried, the data size per page, and the node size includes:
[0085] Substituting the node containing the target page, the target page, the data size per page, and the node size into the preset formula for calculating the query range, we obtain the first parameter. The preset formula for calculating the query range is as follows:
[0086] Size=gotoPage*pageSize-(gotoNode-1)*nodeSize,
[0087] Where gotoPage is the target page for the query, pageSize is the size of each page, gotoNode is the node where the target page is located, nodeSize is the size of the node, and Size is the first parameter.
[0088] In this embodiment, the first parameter represents the number of data entries that need to be skipped after reaching the node containing the target page, i.e., the nearest node. The number of data entries that need to be skipped after reaching the nearest node can be quickly and accurately calculated using the formula for calculating the range of queries.
[0089] Finally, based on the number of valid cache nodes and the first parameter, the ElasticSearch API is called to perform a query and obtain the query results.
[0090] In this embodiment, after determining the number of valid cache nodes, the cache information of node number gotNodeIdx-1 can be obtained accordingly. This information can be used as the searchAfter parameter of the request, and the first parameter can be used as the searchAfter parameter of the request. Then, the ElasticSearch (ES) API is called to query and obtain data by calling the ES query API. The last pageSize of the returned results can be used as the result of this query page to obtain the query result.
[0091] By obtaining the cached information with index gotNodeIdx-1 as the searchAfter parameter of the request, calculating gotoPage*pageSize-(gotoNode-1)*nodeSize as the size parameter to be requested, calling the ES query API to obtain data, and taking the last pageSize of the returned results as the result of this query, the query results can be obtained quickly and accurately, realizing page skipping query.
[0092] Step A3: If it is determined that the node where the target page is located is not in the cached data of the front-end page, cache the block data corresponding to the next node in the back-end data into the cached data of the front-end page to update the cached data of the front-end page, and then switch to execute step A1.
[0093] In this embodiment, if the node containing the target page is not in the cached data of the front-end page, the chunk data corresponding to the next node in the back-end data is cached in the cached data of the front-end page until the node containing the target page is in the cached data of the front-end page. For example, in the above example, if gotoNodeIdx-1 exceeds the current valid cache node count validCount, it means that there is no available cache and it is necessary to go through pagination, that is, to obtain the subsequent node information until the node containing the target page is in the cached data of the front-end page.
[0094] By determining whether the node containing the target page is in the cached data of the front-end page, i.e., whether there is a queryable cache, if it does not exceed the cache limit, the query can be performed in the cached data of the front-end page; if it exceeds the cache limit, the subsequent node information is obtained until the node containing the target page is in the cached data of the front-end page, thereby improving query efficiency and ensuring reliable query execution.
[0095] In some embodiments, caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page and then jumping to execute A1 includes the following steps:
[0096] First, based on the node number of the node where the target page is located and the node number of the current node, the number of nodes to be scrolled forward is calculated;
[0097] In this embodiment, the node containing the target page is not in the cached data of the front-end page. Correspondingly, the node number of the target page's node is also not in the cached data. To ensure the target page's node is included in the front-end page's cached data, the number of nodes to traverse before reaching the target page can be calculated. The node number of the current node refers to the node number in the current cache array. This calculation can be obtained by calculating the difference between the node number of the target page's node and the node number of the current node. For example, the number of nodes to traverse before reaching the target page can be calculated as: gapSizeByNode = gotoNodeIdx - currentNodeIdx, where gotoNodeIdx is the node number of the target page's node, and currentNodeIdx is the node number of the current node.
[0098] Then, determine whether the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes;
[0099] In this embodiment, the maximum allowed number of cached nodes can be pre-configured. If the number of forward nodes exceeds the maximum allowed number of cached nodes, it means that the maximum cache limit has been exceeded, and a prompt message can be generated to indicate that the maximum cache limit has been exceeded.
[0100] Then, if it is determined that the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes, it is determined whether the number of forward-flipped nodes exceeds the maximum number of forward-crossing nodes;
[0101] In this embodiment, the maximum number of nodes to traverse forward can be pre-configured. If the number of nodes to traverse forward exceeds the maximum number of nodes to traverse forward, it indicates that the requirements are not met, and a prompt message can be generated indicating that the maximum page-turning limit has been exceeded. If the number of nodes to traverse forward does not exceed the maximum number of nodes to traverse forward, then the next step is executed.
[0102] Then, if it is determined that the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, the block data corresponding to the next node in the backend data is cached in the cache data of the frontend page to update the cache data of the frontend page, and then jump to execute A1.
[0103] In this embodiment, if the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, it means that the block data corresponding to the next node in the backend data can continue to be cached in the cache data of the frontend page until the node where the target page is located is in the cache data of the frontend page.
[0104] By calculating the number of forward-leaning nodes, the system sequentially checks whether this number exceeds the maximum allowed number of cached nodes and the maximum number of forward-traversing nodes. Only if the number of forward-leaning nodes does not exceed these limits will the next node's corresponding data block from the backend data be cached in the frontend page's cache data, until the target page's node is found in the frontend page's cache data. If not, the query stops, and a corresponding alert is generated to notify the user. This improves query efficiency and reliability.
[0105] In some embodiments, caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page includes:
[0106] First, determine the number of valid cache nodes in the cached data of the front-end page, where the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0107] In this embodiment, the node numbers in the cached data can be numbered sequentially from smallest to largest, and the number of effective cached nodes is the largest node number of the effective cached nodes in the cached data of the front-end page.
[0108] Then, based on the number of valid cache nodes and the node size, the ElasticSearch API is called to perform a query and obtain the returned data;
[0109] In this embodiment, the cache information of the current maximum valid index, i.e. the number of valid cache nodes, can be used as the search_after parameter in the ES request, and the node size nodeSize can be used as the size parameter to call the ES API request and obtain the returned data.
[0110] Finally, the returned data is cached as the block data corresponding to the next node in the cache data of the front-end page to update the cache data of the front-end page.
[0111] In this embodiment, the sort parameter in the returned result can be cached in the data as information for the next node to obtain the block data of the next node. At the same time, the number of effective cached nodes is incremented by 1 to update the cached data of the front-end page.
[0112] By using the cached information of the number of valid cached nodes as the search_after parameter in the ES request and the node size nodeSize as the size parameter when calling the ES API request, the returned data can be obtained quickly and accurately.
[0113] It should be noted that the querying using the ElasticSearch API mentioned in this embodiment is existing technology and will not be elaborated upon here.
[0114] The following example illustrates the query speed achieved using this solution:
[0115] The front-end page caches 1000 key nodes. Assuming each record is viewed in 1 second, a maximum of 60*60*24=86400 records can be viewed in 24 hours. Generally, the maximum number of records per page for easy searching is 500, so a maximum of CEILING(86400 / 500)=173 nodes can be viewed in 24 hours. With a cache of 1000 nodes, it can support continuous viewing for a week, improving query efficiency. In specific implementations, it can also be flexibly expanded through parameter configuration.
[0116] In the above implementation process, the target page is obtained; based on the target page, the preset data size per page, and the node size, the node where the target page is located is determined; based on the node where the target page is located, a query is performed in the cached data of the front-end page to obtain the query results. The cached data of the front-end page is obtained by loading the corresponding block data from the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, each of which is used to store different blocks of data from the back-end data. By determining the node where the target page is located, the node closest to the target page can be determined first, and then the query can start from the node where the target page is located, realizing page skipping query. Random access can also be realized for pages that have been visited, improving the query speed. By caching key node information about the current query conditions through the front-end page, the stateless architecture of the back-end service is maintained. The back-end does not need to cache the node information of each session condition, reducing the pressure on the back-end service and not affecting the scalability of the back-end service. At the same time, according to calculations, the data volume of the front-end caching method will not be large, minimizing the impact on user experience and page performance while meeting the requirements.
[0117] In some embodiments, the following steps are also included:
[0118] First, determine whether the cache of the front-end page has expired;
[0119] Then, if it is determined that the cache of the front-end page is invalid, the cache data is cleared.
[0120] In this embodiment, a cache invalidation strategy can be set for data queries. That is, when the user refreshes or closes the page, resets the query conditions, or exceeds a certain time, the cache can be invalidated, thereby clearing the cache data so that the cache can be updated in the next query.
[0121] In some embodiments, it also includes:
[0122] First, determine whether the current query conditions have changed;
[0123] Then, after determining whether the current query conditions have changed, the cache is initialized, and based on the changed current query conditions, the corresponding block data in the backend data is loaded into the frontend page cache.
[0124] In this embodiment, when the value in the query condition changes, it is considered that the current query condition has changed. The page can then be reloaded to initialize the cache. Based on the changed current query condition, the corresponding block data in the backend data is loaded into the frontend page cache to update the cache in real time, so as to be suitable for different use cases.
[0125] Please refer toFigure 3 , Figure 3 The diagram illustrates the detailed process of page skipping query according to an embodiment of this application. The solution will be described in detail below with specific examples.
[0126] First, UI events can be determined through user interface actions. When the UI event is page initial load, the cache node configuration is obtained and the cache array is initialized. When the UI event is a query event, the node where gotoPage is located, gotoNodeIdx = Ceiling(gotoPage*pageSize / nodeSize), is calculated. Then, it is checked whether gotoNodeIdx-1 is greater than validCount. If so, it means there is no cache, and page forward is required; otherwise, it means that cached nodes are being paged. In the case of paged cached nodes, the cache information at index gotNodeIdx-1 is obtained and used as the searchAfter parameter of the request. gotoPage*pageSize-(gotoNode-1)*nodeSize is calculated as the size parameter to be requested. The Elasticsearch query API is called to retrieve data, and the last pageSize-sized data in the returned results is taken as the result of this query and returned. When forward pagination is required, first calculate the number of nodes to be paginated: gapSizeByNode = gotoNodeIdx - currentNodeIdx. Then, check if gapSizeByNode exceeds the maxCachedNodeSize limit. If it does, indicate that the maximum cache limit has been exceeded. If it does not exceed the limit, check if it exceeds the maxPosGapSizeByNode limit. If it does, indicate that the maximum single pagination limit {maxGapSizeByNode * nodeSize} has been exceeded. If it does not exceed the limit, obtain the current valid cache count (validCount) as the maximum valid index, obtain nodeCache[validCount] as the searchAfter parameter of the request, obtain nodeSize as the size parameter of the request, call the Elasticsearch query API to retrieve data, and store the sorted content from the returned result as the information of the new node at the cache index (validCount + 1). Increment the validCount value by 1, and return to check if gotoNodeIdx - 1 is greater than validCount. When the query condition fields change, re-execute the page initial load event. When the interface event is page close / exit, clear the cache.
[0127] Figure 2 This is a flowchart illustrating a page skipping query method in one embodiment. It should be understood that, although... Figure 2The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0128] In one embodiment, such as Figure 4 As shown, a page skipping query device is provided, including an acquisition module 410, a determination module 420, and a query module 430, wherein:
[0129] Module 410 is used to retrieve the target page for the query.
[0130] The determination module 420 is used to determine the node where the target page is located based on the target page, the preset data size per page, and the node size.
[0131] The query module 430 is used to query the cached data of the front-end page based on the node where the target page is located, and obtain the query result. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, and each node is used to store different blocks of data in the back-end data.
[0132] The query module 430 includes:
[0133] The first judgment unit is used to determine whether the node where the target page is located is in the cached data of the front-end page;
[0134] The first query unit is used to query the cached data of the front-end page based on the node where the target page is located, and obtain the query result, when it is determined that the node where the target page is located is in the cached data of the front-end page.
[0135] The second query unit is used to cache the block data corresponding to the next node in the backend data into the cache data of the frontend page when it is determined that the node where the target page is located is not in the cache data of the frontend page, so as to update the cache data of the frontend page and call the first judgment unit.
[0136] The second query unit includes:
[0137] The first calculation subunit is used to calculate the number of previous nodes based on the node number of the node where the target page is located and the node number of the current node.
[0138] The first judgment subunit is used to determine whether the number of forward-flipping nodes exceeds the maximum allowed number of cached nodes;
[0139] The second judgment subunit is used to determine whether the number of forward-crossing nodes exceeds the maximum allowed number of cached nodes when it is determined that the number of forward-crossing nodes exceeds the maximum number of forward-crossing nodes.
[0140] The update subunit is used to cache the block data corresponding to the next node in the backend data into the cache data of the frontend page when it is determined that the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, so as to update the cache data of the frontend page and call the first judgment unit.
[0141] The second query unit includes:
[0142] The first determining subunit is used to determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0143] The first query subunit is used to call the ElasticSearch API to query based on the number of valid cache nodes and the node size, and obtain the returned data;
[0144] The caching subunit is used to cache the returned data as the block data corresponding to the next node in the cache data of the front-end page, so as to update the cache data of the front-end page.
[0145] The first query unit includes:
[0146] The second determining subunit is used to determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0147] The second calculation subunit is used to calculate a first parameter based on the node where the target page is located, the target page being queried, the data size per page, and the node size. The first parameter is used to represent the number of data items that need to be skipped after reaching the node where the target page is located.
[0148] The second query subunit is used to call the ElasticSearch API to perform a query based on the number of valid cache nodes and the first parameter, and obtain the query results.
[0149] The second calculation subunit calculates the first parameter based on the node where the target page is located, the target page being queried, the data size per page, and the node size, including:
[0150] Substituting the node containing the target page, the target page, the data size per page, and the node size into the preset formula for calculating the query range, we obtain the first parameter. The preset formula for calculating the query range is as follows:
[0151] Size=gotoPage*pageSize-(gotoNode-1)*nodeSize,
[0152] Where gotoPage is the target page for the query, pageSize is the size of each page, gotoNode is the node where the target page is located, nodeSize is the size of the node, and Size is the first parameter.
[0153] This also includes:
[0154] The first judgment module is used to determine whether the cache of the front-end page has expired;
[0155] The clear module is used to clear the cached data when it is determined that the cache of the front-end page has expired.
[0156] This also includes:
[0157] The second judgment module is used to determine whether the current query conditions have changed;
[0158] The initialization module is used to initialize the cache when it is determined whether the current query conditions have changed, and to load the corresponding block data in the backend data into the frontend page cache based on the changed current query conditions.
[0159] The determining module 420 includes:
[0160] The node calculation unit is used to substitute the target page, the preset page size, and the node size into a preset node calculation formula to obtain the node where the target page is located. The preset node calculation formula is: gotoNodeIdx = Ceiling(gotoPage * pageSize / nodeSize).
[0161] Where gotoNodeIdx is the node where the target page is located, gotoPage is the target page for the query, pageSize is the size of the data per page, and nodeSize is the size of the node.
[0162] The page skipping query device includes a processor and a memory. The aforementioned acquisition module 410, determination module 420, and query module 430 are all stored in the memory as program units, and the processor executes the aforementioned program modules stored in the memory to implement the corresponding functions.
[0163] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and page skipping methods can be implemented by adjusting kernel parameters.
[0164] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0165] This application provides a machine-readable storage medium storing a program that, when executed by a processor, implements the above-described page skipping query method.
[0166] This application provides a processor for running a program, wherein the program executes the above-described page skipping query method during runtime.
[0167] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown in the figure, the computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements a page-skipping query method. The display screen A04 can be a liquid crystal display (LCD) or an e-ink display. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0168] Those skilled in the art will understand that Figure 5The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0169] In one embodiment, the process approval processing device provided in this application can be implemented as a computer program, and the computer program can be implemented in such a way as... Figure 5 It runs on the computer device shown. The computer device's memory can store the various program modules that make up the process approval and processing unit, for example, Figure 4 The acquisition module 410, determination module 420, and query module 430 are shown. The computer program comprised of these modules causes the processor to execute the steps of the process approval method described in the various embodiments of this application.
[0170] Figure 5 The computer equipment shown can be used as follows Figure 4 The acquisition module 410 in the process approval processing device shown executes step 210. The computer device can execute step 220 through the determination module 420 and step 230 through the query module 430.
[0171] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the following method steps:
[0172] Retrieve the target page for the query;
[0173] Based on the target page, the preset data size per page, and the node size, the node where the target page is located is determined;
[0174] Based on the node where the target page is located, a query is performed in the cached data of the front-end page to obtain the query result. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, each node is used to store different blocks of data in the back-end data.
[0175] In one embodiment, the step of querying the cached data of the front-end page based on the node where the target page is located to obtain the query results includes:
[0176] A1: Determine whether the node containing the target page is in the cached data of the front-end page;
[0177] A2: If it is determined that the node where the target page is located is in the cached data of the front-end page, a query is performed in the cached data of the front-end page based on the node where the target page is located to obtain the query result;
[0178] A3: If it is determined that the node where the target page is located is not in the cached data of the front-end page, cache the block data corresponding to the next node in the back-end data into the cached data of the front-end page to update the cached data of the front-end page, and then jump to execute A1.
[0179] In one embodiment, caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page, and then jumping to execute A1, includes:
[0180] The number of nodes to be scrolled forward is calculated based on the node number of the target page and the node number of the current node.
[0181] Determine whether the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes;
[0182] If it is determined that the number of forward-crossing nodes exceeds the maximum allowed number of cached nodes, it is then determined whether the number of forward-crossing nodes exceeds the maximum number of forward-traversing nodes.
[0183] If it is determined that the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, the block data corresponding to the next node in the backend data is cached in the cache data of the frontend page to update the cache data of the frontend page, and then jump to execute A1.
[0184] In one embodiment, caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page includes:
[0185] Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0186] Based on the number of valid cache nodes and the node size, the ElasticSearch API is called to perform a query and obtain the returned data;
[0187] The returned data is cached as the block data corresponding to the next node in the cache data of the front-end page, so as to update the cache data of the front-end page.
[0188] In one embodiment, the step of querying the cached data of the front-end page based on the node where the target page is located to obtain the query results includes:
[0189] Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page;
[0190] Based on the node where the target page is located, the target page, the data size per page, and the node size, a first parameter is calculated. The first parameter is used to represent the number of data items that need to be skipped after reaching the node where the target page is located.
[0191] Based on the number of valid cache nodes and the first parameter, the ElasticSearch API is called to perform a query and obtain the query results.
[0192] In one embodiment, the calculation of the first parameter based on the node where the target page is located, the target page being queried, the data size per page, and the node size includes:
[0193] Substituting the node containing the target page, the target page, the data size per page, and the node size into the preset formula for calculating the query range, we obtain the first parameter. The preset formula for calculating the query range is as follows:
[0194] Size=gotoPage*pageSize-(gotoNode-1)*nodeSize,
[0195] Where gotoPage is the target page for the query, pageSize is the size of each page, gotoNode is the node where the target page is located, nodeSize is the size of the node, and Size is the first parameter.
[0196] In one embodiment, it also includes:
[0197] Determine whether the cache of the front-end page has expired;
[0198] If the cache of the front-end page is determined to be invalid, the cached data shall be cleared.
[0199] In one embodiment, it also includes:
[0200] Determine whether the current query conditions have changed;
[0201] If it is determined whether the current query conditions have changed, the cache is initialized, and based on the changed current query conditions, the corresponding block data in the backend data is loaded into the frontend page cache.
[0202] In one embodiment, determining the node containing the target page based on the target page, a preset page size, and a node size includes:
[0203] Substituting the target page, the preset page size, and the node size into a pre-defined node calculation formula, the node containing the target page is obtained. The pre-defined node calculation formula is as follows:
[0204] gotoNodeIdx=Ceiling(gotoPage*pageSize / nodeSize),
[0205] Where gotoNodeIdx is the node where the target page is located, gotoPage is the target page for the query, pageSize is the size of the data per page, and nodeSize is the size of the node.
[0206] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0207] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0208] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0209] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0210] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0211] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0212] Computer-readable media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0213] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0214] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for skipping pages in search, characterized in that, The page skipping query method includes: Retrieve the target page for the query; Based on the target page, the preset data size per page, and the node size, the node where the target page is located is determined; Based on the node where the target page is located, a query is performed in the cached data of the front-end page to obtain the query result. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, each node is used to store different blocks of data in the back-end data.
2. The method according to claim 1, characterized in that, The query, based on the node where the target page is located, is performed in the cached data of the front-end page to obtain the query results, including: A1: Determine whether the node containing the target page is in the cached data of the front-end page; A2: If it is determined that the node where the target page is located is in the cached data of the front-end page, a query is performed in the cached data of the front-end page based on the node where the target page is located to obtain the query result; A3: If it is determined that the node where the target page is located is not in the cached data of the front-end page, cache the block data corresponding to the next node in the back-end data into the cached data of the front-end page to update the cached data of the front-end page, and then jump to execute A1.
3. The method according to claim 2, characterized in that, The step of caching the block data corresponding to the next node in the backend data into the cache data of the frontend page to update the cache data of the frontend page and then jumping to execute A1 includes: The number of nodes to be scrolled forward is calculated based on the node number of the target page and the node number of the current node. Determine whether the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes; If it is determined that the number of forward-flipped nodes exceeds the maximum allowed number of cached nodes, it is then determined whether the number of forward-flipped nodes exceeds the maximum number of forward-crossing nodes. If it is determined that the number of forward-crossing nodes does not exceed the maximum number of forward-crossing nodes, the block data corresponding to the next node in the backend data is cached in the cache data of the frontend page to update the cache data of the frontend page, and then jump to execute A1.
4. The method according to claim 2, characterized in that, The step of caching the block data corresponding to the next node in the backend data to the cache data of the frontend page, so as to update the cache data of the frontend page, includes: Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page; Based on the number of valid cache nodes and the node size, the ElasticSearch API is called to perform a query and obtain the returned data; The returned data is cached as the block data corresponding to the next node in the cache data of the front-end page, so as to update the cache data of the front-end page.
5. The method according to claim 2, characterized in that, The query, based on the node where the target page is located, is performed in the cached data of the front-end page to obtain the query results, including: Determine the number of valid cache nodes in the cached data of the front-end page, wherein the number of valid cache nodes is the maximum node number of the valid cache nodes in the cached data of the front-end page; Based on the node where the target page is located, the target page, the data size per page, and the node size, a first parameter is calculated. The first parameter is used to represent the number of data items that need to be skipped after reaching the node where the target page is located. Based on the number of valid cache nodes and the first parameter, the ElasticSearch API is called to perform a query and obtain the query results.
6. The method according to claim 5, characterized in that, The first parameter is calculated based on the node where the target page is located, the target page being queried, the data size per page, and the node size, including: Substituting the node containing the target page, the target page, the data size per page, and the node size into the preset formula for calculating the query range, we obtain the first parameter. The preset formula for calculating the query range is as follows: Size=gotoPage*pageSize-(gotoNode-1)*nodeSize, Where gotoPage is the target page for the query, pageSize is the size of each page, gotoNode is the node where the target page is located, nodeSize is the size of the node, and Size is the first parameter.
7. The method according to claim 1, characterized in that, Also includes: Determine whether the cache of the front-end page has expired; If the cache of the front-end page is determined to be invalid, the cached data shall be cleared.
8. The method according to claim 1, characterized in that, Also includes: Determine whether the current query conditions have changed; If it is determined whether the current query conditions have changed, the cache is initialized, and based on the changed current query conditions, the corresponding block data in the backend data is loaded into the frontend page cache.
9. The method according to claim 1, characterized in that, The step of determining the node containing the target page based on the target page, the preset data size per page, and the node size includes: Substituting the target page, the preset page size, and the node size into a pre-defined node calculation formula, the node containing the target page is obtained. The pre-defined node calculation formula is as follows: gotoNodeIdx=Ceiling(gotoPage*pageSize / nodeSize), Where gotoNodeIdx is the node where the target page is located, gotoPage is the target page for the query, pageSize is the size of the data per page, and nodeSize is the size of the node.
10. A page-skipping query device, characterized in that, The page skipping query device includes: The retrieval module is used to retrieve the target page for the query. The determination module is used to determine the node where the target page is located based on the target page, the preset data size per page, and the node size. The query module is used to query the cached data of the front-end page based on the node where the target page is located, and obtain the query results. The cached data of the front-end page is obtained by loading the corresponding block data in the back-end data into the front-end page cache based on the current query conditions. The cached data of the front-end page includes multiple nodes, and each node is used to store different blocks of data in the back-end data.
11. A processor, characterized in that, It is configured to perform the page skipping query method according to any one of claims 1 to 9.
12. A machine-readable storage medium storing instructions thereon, characterized in that, When executed by a processor, this instruction causes the processor to be configured to perform the page skipping query method according to any one of claims 1 to 9.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the page skipping query method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Cache data paging query method and system and computer readable storage medium
CN111367952A
Elasticsearch paging data query method and device
CN111680063A