File query method and device based on adjacency list and computer device

By splitting the full file path into sub-paths and querying them asynchronously, the problem of low query efficiency when there are many path levels is solved, achieving efficient file location and improving user experience.

CN116303264BActive Publication Date: 2026-04-07E-SURFING DIGITAL LIFE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-30
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, the more path levels a file's complete path has, the lower the query and location efficiency and the longer it takes.

Method used

By obtaining the path hierarchy of the complete file path, it is determined whether it exceeds a preset threshold. If it does, the path is split into a first sub-path and a second sub-path, and queries are performed asynchronously to obtain the file objects under the first sub-path and the list of file objects under the second sub-path, respectively. Finally, the target file is retrieved from the database.

Benefits of technology

In cases with multiple path levels, it improves query and location efficiency, reduces file query time, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116303264B_ABST
    Figure CN116303264B_ABST
Patent Text Reader

Abstract

The file query method, apparatus, and computer device based on adjacency lists provided in this application allow users to first obtain the complete file path of the target file to be queried when they need to query related files. The path level of this complete file path is then determined. If the path level is greater than a preset level threshold, the complete file path can be split into a first sub-path and a second sub-path. The first and second sub-paths are then queried according to preset file query rules, resulting in a first file object queried under the first sub-path and a list of file objects queried under the second sub-path. Next, this application can find a second file object corresponding to the first file object from the list of file objects and retrieve the target file from the database based on the second file object. This effectively improves query and location efficiency, reduces file query time, and enhances user experience.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software development, and particularly relates to a file query method and device based on an adjacency list and a computer device. BACKGROUND

[0002] A tree structure is a hierarchical nested structure, and the outer layer and the inner layer of a tree structure have similar structures, so the structure can be recursively represented. Various tree-shaped graphs in classic data structures are a typical tree structure, and the tree structure is a data structure in which there is a "one-to-many" tree relationship between data elements, and is an important nonlinear data structure. In the tree structure, the root node of the tree has no predecessor node, and each of the remaining nodes has only one predecessor node. Each of the remaining nodes has no successor node, and the number of successor nodes of each of the remaining nodes can be one or more.

[0003] At present, an adjacency list is mainly used as a tree structure storage model on the market. For a network disk business designed by an adjacency list storage, when a user inputs a complete file path in the front end, the corresponding file or folder needs to be quickly located according to the complete file path, and a file list under the current folder is returned. However, when the path level in the complete file path is more, the query positioning efficiency is also lower, and the time consumption is also longer. SUMMARY

[0004] The present application aims to at least solve one of the above technical defects, and particularly aims to solve the technical defect that the query positioning efficiency is lower and the time consumption is longer when the path level in the complete file path is more in the prior art.

[0005] The present application provides a file query method based on an adjacency list, which comprises the following steps:

[0006] A complete file path corresponding to a target file to be queried is obtained, and a path level of the complete file path is determined.

[0007] If the path level is not greater than a preset level threshold, the target file is obtained by sequentially querying according to the path order between each layer path in the complete file path.

[0008] If the path level is greater than the preset level threshold, the complete file path is split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path are respectively queried according to a preset file query rule, to obtain a first file object under the first sub-path and a file object list under the second sub-path.

[0009] A second file object corresponding to the first file object is searched from the file object list, and the target file is obtained from a database according to the second file object.

[0010] Optionally, obtaining the target file by sequentially querying according to the path order between each level of the complete file path includes:

[0011] According to the path order between the paths in the complete file path, obtain the path name of the current path from the complete file path and obtain the parent file ID of the current path from the file object queried from the previous path, wherein the parent file ID of the first path in the complete file path is empty;

[0012] The database is queried based on the path name and parent file ID of the current path, and the file objects under the current path are returned by the database.

[0013] Determine whether the current path is the last level path in the complete file path;

[0014] If so, the file object under the current path will be used as the target file;

[0015] Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the complete file path and obtaining the parent file ID of the current path from the file object queried from the previous level path.

[0016] Optionally, before determining whether the current path is the last level path in the complete file path, the method further includes:

[0017] Determine whether the file object in the current path is empty;

[0018] If the value is empty, the query operation will stop.

[0019] If it is not empty, then the step of determining whether the current path is the last level path in the complete path of the file is executed.

[0020] Optionally, the first sub-path contains the first-level path in the complete file path, and the second sub-path contains the last-level path in the complete file path;

[0021] The process involves querying the first subpath and the second subpath according to preset file query rules to obtain a list of first file objects under the first subpath and a list of file objects under the second subpath, including:

[0022] Using the first-level path in the complete file path as the first-level path in the first sub-path, the first file object under the first sub-path is obtained by sequentially querying according to the path order between each level of the first sub-path.

[0023] Using the last level of the complete file path as the first level of the second sub-path, and querying sequentially from the last level upwards according to the path order of each level of the second sub-path, a list of file objects under the second sub-path is obtained.

[0024] Optionally, obtaining the first file object under the first sub-path by sequentially querying according to the path order between each level of the first sub-path includes:

[0025] According to the path order between the paths in the first sub-path, the path name of the current path is obtained from the first sub-path and the parent file ID of the current path is obtained from the file object queried from the previous path. The parent file ID of the first path in the first sub-path is empty.

[0026] The database is queried based on the path name and parent file ID of the current path, and the file objects under the current path are returned by the database.

[0027] Determine whether the current path is the last level path in the first sub-path;

[0028] If so, the file object under the current path is taken as the first file object under the first subpath;

[0029] Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the first sub-path and obtaining the parent file ID of the current path from the file object queried from the previous level path.

[0030] Optionally, the step of querying from the last level upwards according to the path order of each level in the second sub-path to obtain the list of file objects under the second sub-path includes:

[0031] According to the path order between the paths in the second sub-path, the path name of the current path is obtained from the second sub-path, and the parent file ID obtained from the list of file objects queried under the previous path is used as the file ID of the current path. The first path in the second sub-path is the list of file objects obtained by querying the database using its path name.

[0032] The database is queried based on the path name and file ID of the current path, and a list of file objects under the current path is returned by the database.

[0033] Determine whether the current path is the last level path in the second sub-path;

[0034] If so, the list of file objects under the current path will be used as the list of file objects under the second subpath;

[0035] Otherwise, after replacing the next level path of the current path with the current path, return to the step of obtaining the path name of the current path from the two sub-paths and using the parent file ID obtained from the list of file objects queried under the previous level path as the file ID of the current path.

[0036] Optionally, the method further includes:

[0037] If the first file object found under any level of the first sub-path is empty, or if the list of file objects found under any level of the second sub-path is empty, then the query operation is stopped.

[0038] Optionally, the first level path in the second sub-path is the last level path in the complete file path;

[0039] The step of searching for a second file object corresponding to the first file object from the file object list, and retrieving the target file from the database based on the second file object, includes:

[0040] Obtain at least one parent file ID corresponding to the last path in the second sub-path from the list of file objects, and obtain the corresponding file ID from the first file object;

[0041] Each parent file ID is compared with the file ID, and the file object corresponding to the parent file ID that is the same as the file ID is taken as the second file object. The second file object contains the file ID of the leaf node in the list of file objects queried from the first-level path of the second sub-path.

[0042] The database is searched for the file object corresponding to the file ID of the leaf node, and the file object is used as the target file.

[0043] This application also provides a file query device based on an adjacency list, including:

[0044] The path acquisition module is used to obtain the complete file path corresponding to the target file to be queried, and to determine the path level of the complete file path;

[0045] The first query module is used to obtain the target file by sequentially querying the paths in the complete file path according to the path order between each level if the path level is not greater than a preset level threshold.

[0046] The second query module is used to split the complete file path into a first sub-path and a second sub-path if the path level is greater than the preset level threshold, and to query the first sub-path and the second sub-path respectively according to the preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path.

[0047] The file acquisition module is used to search for a second file object corresponding to the first file object from the file object list, and to retrieve the target file from the database based on the second file object.

[0048] This application also provides a computer device, including: one or more processors, and memory;

[0049] The memory stores computer-readable instructions, which, when executed by the one or more processors, perform the steps of the file query method based on an adjacency list as described in any of the above embodiments.

[0050] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0051] The file query method, apparatus, and computer device based on adjacency lists provided in this application, when a user needs to query related files, can first obtain the complete file path corresponding to the target file to be queried and determine the path level of the complete file path. Then, the path level is judged. If the path level is not greater than a preset level threshold, the target file can be obtained by querying the path order between each level of the complete file path. If the path level is greater than the preset level threshold, it indicates that there are many path levels in the current complete file path. At this time, the complete file path can be split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path can be queried according to the preset file query rules respectively, and the first file object queried under the first sub-path and the list of file objects queried under the second sub-path can be obtained. Then, this application can find the second file object corresponding to the first file object from the list of file objects, and retrieve the target file from the database based on the second file object. This process can be executed asynchronously and simultaneously, thereby effectively improving the query and positioning efficiency, reducing the file query time, and improving the user experience when there are many path levels in the complete file path. Attached Figure Description

[0052] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0053] Figure 1 A flowchart illustrating a file query method based on an adjacency list provided in this application embodiment;

[0054] Figure 2 A schematic diagram of a page for obtaining the complete file path as provided in an embodiment of this application;

[0055] Figure 3 A schematic diagram of a file query device based on an adjacency list provided in this application embodiment;

[0056] Figure 4 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of this application. Detailed Implementation

[0057] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0058] Currently, adjacency lists are mainly used as tree-structured storage models in the market. For cloud storage services designed with adjacency lists, when a user enters a complete file path on the front end, it is necessary to quickly locate the corresponding file or folder based on the complete file path and return the list of files in the current folder. However, the more path levels in the complete file path, the lower the query and location efficiency and the longer the time consumption.

[0059] Based on this, this application proposes the following technical solution, as detailed below:

[0060] In one embodiment, such as Figure 1 As shown, Figure 1 This application provides a flowchart illustrating a file query method based on an adjacency list. The application provides a file query method based on an adjacency list, which may include:

[0061] S110: Obtain the complete file path corresponding to the target file to be queried, and determine the path level of the complete file path.

[0062] In this step, when a user wants to query a target file, they can obtain the complete file path corresponding to the target file to be queried and determine the path hierarchy of the complete file path. In this way, they can perform the query using the appropriate query strategy to improve query efficiency.

[0063] Understandably, files are typically stored in databases in a specific format, such as a tree structure storage model. A tree structure is a hierarchical nested structure. In a tree structure, the root node has no predecessor node, each of the remaining nodes has exactly one predecessor node, leaf nodes have no successor nodes, and each of the remaining nodes can have one or more successor nodes. Therefore, the complete file path of the target file to be queried obtained in this application can include one or more path levels, each path level corresponding to a root node or leaf node of the tree structure.

[0064] Indicatively, such as Figure 2 As shown, Figure 2 A schematic diagram of a page for obtaining the complete file path as provided in an embodiment of this application; Figure 2 In this context, users can use a cloud storage client or web interface to pass in a complete file path (e.g., / all files / 1234567890 / 1234567890 / 123 / 1234 / 12345). The number of " / " characters in the complete file path can be used to determine the path level of the file path, and the number of path levels can be used to determine the query strategy to be used.

[0065] S120: If the path level is not greater than the preset level threshold, the target file is obtained by querying the path order between each level of the complete file path.

[0066] In this step, after obtaining the complete file path corresponding to the target file to be queried through S110 and determining the path level of the complete file path, this application can continue to determine whether the path level of the complete file path is greater than the preset level threshold. If it is not greater than the threshold, it means that the current complete file path has fewer path levels. At this time, the target file can be obtained by querying in the order of the paths between each level of the complete file path.

[0067] For example, when a user passes a complete file path (e.g., / all files / 1234567890 / 1234567890 / 123 / 1234 / 12345) using a cloud storage client or web application, the path level of the complete file path can be determined by the number of " / " characters in the path. If the path level is not greater than a preset level threshold, the folder can be quickly located using the path " / all files / 1234567890", and the file list " / 1234567890 / 123 / 1234 / 12345" in the current folder can be returned. Users can then add, modify, or delete files within the folder without any restrictions.

[0068] Furthermore, the preset level threshold in this application can be set according to the actual situation. For example, in the actual file query process, when the path level of the complete file path exceeds 3 levels, the speed of returning the target file during file query will decrease significantly. At this time, the preset level threshold can be set to 3 levels. For complete file paths with fewer than 3 levels, the target file can be obtained by querying in the order of the paths between each level of the complete file path. For complete file paths with more than 3 levels, the file query operation can be performed in the following way to improve the efficiency of file query.

[0069] S130: If the path level is greater than the preset level threshold, the complete file path is split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path are queried according to the preset file query rules to obtain the first file object under the first sub-path and the list of file objects under the second sub-path.

[0070] In this step, after obtaining the complete file path corresponding to the target file to be queried through S110 and determining the path level of the complete file path, this application can continue to determine whether the path level of the complete file path is greater than a preset level threshold. If it is greater, it means that the current complete file path has a large number of path levels. In order to avoid the phenomenon of low query efficiency caused by querying in the order of the paths between the different levels of the complete file path, this application can split the complete file path into two sub-paths and perform file queries on the two sub-paths asynchronously at the same time, thereby improving the file query efficiency.

[0071] Specifically, this application can split a complete file path into a first sub-path and a second sub-path when the path level of the complete file path exceeds a preset level threshold. After splitting, the first sub-path and the second sub-path are queried according to preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path. For example, this application can split the complete file path according to its path level, such as dividing the path below the preset level threshold into the first sub-path and the path exceeding the preset level threshold into the second sub-path. Alternatively, the path level n of the complete file path can be divided by 2 and rounded to obtain m. Then, the paths from level 1 to m are placed into array 1 as the first sub-path and the paths from level m to n are placed into array 2 as the second sub-path. Thread 1 is started to process the data in array 1, and thread 2 is started to process the data in array 2, and the processing results of thread 1 and thread 2 are obtained.

[0072] Understandably, the above-described splitting method ensures that after splitting the complete file path, the first sub-path contains the first level path of the complete file path, and the second sub-path contains the last level path of the complete file path. This saves time in searching for the target file and further improves file query efficiency. Of course, this application can also split the complete file path in other ways, which will not be elaborated here.

[0073] S140: Find the second file object corresponding to the first file object from the file object list, and retrieve the target file from the database based on the second file object.

[0074] In this step, after querying the first sub-path and the second sub-path according to the preset file query rules in S130, since the first sub-path contains the first level path of the complete file path and the second sub-path contains the last level path of the complete file path, the first file object under the first sub-path and the list of file objects under the second sub-path can be obtained in the above way. Then, this application can find the second file object corresponding to the first file object from the list of file objects and obtain the target file from the database based on the second file object.

[0075] It should be noted that when the second subpath in this application contains the last level of the complete file path, since the file directory tree structure is a one-to-many relationship, the list of file objects obtained after querying the second subpath may contain target files under the second subpath as well as target files under other paths. Based on this, after obtaining the first file object and the list of file objects, this application can search for the second file object corresponding to the first file object in the list of file objects, so as to find the file object under the same path as the complete file path in the list of file objects, and retrieve the target file from the database through the second file object. The target file retrieved at this time is the target file under the complete file path.

[0076] In the above embodiments, when a user needs to query related files, the complete file path corresponding to the target file to be queried can be obtained first, and the path level of the complete file path can be determined. Then, the path level is judged. If the path level is not greater than a preset level threshold, the target file can be obtained by querying the path order between each level of the complete file path. If the path level is greater than the preset level threshold, it indicates that there are many path levels in the current complete file path. At this time, the complete file path can be split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path can be queried according to the preset file query rules respectively, and the first file object queried under the first sub-path and the list of file objects queried under the second sub-path can be obtained. Then, this application can find the second file object corresponding to the first file object from the list of file objects, and obtain the target file from the database based on the second file object. This process can be executed asynchronously and simultaneously, thereby effectively improving the query and positioning efficiency, reducing the file query time, and improving the user experience when there are many path levels in the complete file path.

[0077] In one embodiment, S120, which involves sequentially querying the target file according to the path order of each level of the complete file path to obtain the target file, may include:

[0078] S121: According to the path order between the paths of each level in the complete file path, obtain the path name of the current path from the complete file path and obtain the parent file ID of the current path from the file object queried from the previous level path, wherein the parent file ID of the first level path in the complete file path is empty.

[0079] S122: Perform a query operation on the database based on the path name and parent file ID of the current path, and obtain the file object under the current path returned by the database.

[0080] S123: Determine whether the current path is the last level path in the complete file path.

[0081] S124: If so, then the file object under the current path will be used as the target file.

[0082] S125: Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the complete file path and obtaining the parent file ID of the current path from the file object queried from the previous level path.

[0083] In this embodiment, when the path level of the complete file path is not greater than a preset level threshold, the target file can be obtained by sequentially querying the path order between each level of the complete file path.

[0084] Specifically, this application can obtain the path name of the current path from the complete file path and the parent file ID of the current path from the file objects retrieved from the previous level path, following the path order between the different levels of the complete file path. If the current path is the first level path, the parent file ID of the current path is empty. After obtaining the path name and parent file ID of the current path, a query operation can be performed on the database based on the path name and parent file ID of the current path, and the file objects under the current path returned by the database can be obtained. Then, this application can determine whether the current path is the last level path in the complete file path. If it is, the file objects under the current path are used as the target file. If not, the next level path of the current path can be used as the current path, and the path name of the current path and the parent file ID of the current path can be obtained from the file objects retrieved from the previous level path. The database can then be queried based on the path name and parent file ID of the current path, and the file objects under the current path returned by the database can be obtained, until the current path is the last level path in the complete file path.

[0085] In one embodiment, before determining whether the current path is the last level path in the complete file path in step S123, the following may be included:

[0086] S1221: Determine whether the file object in the current path is empty.

[0087] S1222: If empty, stop the query operation.

[0088] S1223: If not empty, then perform the step of determining whether the current path is the last level path in the complete file path.

[0089] In this embodiment, before determining whether the current path is the last level path in the complete file path, this application can also determine whether the file object of the current path is empty. If it is empty, it means that no relevant data can be found in the database based on the path name and parent file ID of the current path. At this time, the query operation can be stopped. If it is not empty, the application can continue to determine whether the current path is the last level path in the complete file path.

[0090] In one embodiment, the first sub-path contains the first-level path in the complete file path, and the second sub-path contains the last-level path in the complete file path. In step S130, the first sub-path and the second sub-path are queried according to preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path, which may include:

[0091] S131: Using the first-level path in the complete file path as the first-level path in the first sub-path, query sequentially according to the path order between each level of the first sub-path to obtain the first file object under the first sub-path.

[0092] S132: Using the last level path in the complete file path as the first level path in the second sub-path, query from the last level path upwards according to the path order between each level path in the second sub-path to obtain the list of file objects under the second sub-path.

[0093] In this embodiment, when the path level of the complete file path is greater than a preset level threshold, the complete file path can be split into a first sub-path and a second sub-path. After splitting, the first sub-path and the second sub-path are queried according to preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path.

[0094] Specifically, after splitting the complete file path into a first sub-path and a second sub-path, the first sub-path contains the first-level path of the complete file path, and the second sub-path contains the last-level path of the complete file path. Thus, when querying the first sub-path and the second sub-path respectively, the first-level path of the complete file path can be used as the first-level path of the first sub-path, and the query can be performed sequentially according to the path order between the various levels of the first sub-path to obtain the first file object under the first sub-path. At the same time, the application can also use the last-level path of the complete file path as the first-level path of the second sub-path, and perform the query sequentially from the last level of the second sub-path upwards according to the path order between the various levels of the second sub-path to obtain the list of file objects under the second sub-path, thereby improving the efficiency of file query.

[0095] In one embodiment, S131, which involves sequentially querying the paths in the first sub-path according to their order to obtain the first file object under the first sub-path, may include:

[0096] S1310: According to the path order between the paths in the first sub-path, obtain the path name of the current path from the first sub-path and obtain the parent file ID of the current path from the file object queried from the previous path, wherein the parent file ID of the first path in the first sub-path is empty.

[0097] S1311: Perform a query operation on the database based on the path name and parent file ID of the current path, and obtain the file object under the current path returned by the database.

[0098] S1312: Determine whether the current path is the last level path in the first sub-path.

[0099] S1313: If so, then the file object under the current path is taken as the first file object under the first subpath.

[0100] S1314: Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the first sub-path and obtaining the parent file ID of the current path from the file object queried from the upper level path.

[0101] In this embodiment, when querying the first sub-path, the first-level path in the complete file path can be used as the first-level path in the first sub-path, and the query can be performed sequentially according to the path order between each level of the first sub-path to obtain the first file object under the first sub-path.

[0102] Specifically, this application can obtain the path name of the current path from the first sub-path and the parent file ID of the current path from the file objects retrieved from the previous level path, according to the path order between the different levels of the first sub-path. If the current path is the first level path, the parent file ID of the current path is empty. After obtaining the path name and parent file ID of the current path, a query operation can be performed on the database based on the path name and parent file ID of the current path, and the file objects under the current path returned by the database can be obtained. Then, this application can determine whether the current path is the last level path in the first sub-path. If it is, the file objects under the current path are taken as the first file objects. If not, the next level path of the current path can be taken as the current path, and the path name of the current path and the parent file ID of the current path can be obtained from the first sub-path. The database can be queried based on the path name and parent file ID of the current path, and the file objects under the current path returned by the database can be obtained, until the current path is the last level path in the first sub-path.

[0103] For example, this application can first obtain the name of the first-level path in the first sub-path, and then query the current user's file records from the database. The query conditions are files whose parent file ID is empty and whose file name is the same as the name of the first-level path, resulting in file object a. Then, this application can obtain the parent file ID (e.g., fileId1) from file object a, query the database, and the query conditions are files whose parent file ID is fileId1 and whose file name is the same as the name of the second-level path, resulting in file object b. And so on, until finally obtaining file object 1 of the m-th level.

[0104] In one embodiment, S132, which involves querying the file objects under the second sub-path sequentially from the last level upwards according to the path order among the different levels of the second sub-path, may include:

[0105] S1320: According to the path order between the paths of each layer in the second sub-path, obtain the path name of the current path from the second sub-path and the parent file ID obtained from the list of file objects queried under the previous layer path as the file ID of the current path. The first layer path in the second sub-path is the list of file objects obtained by querying the database using its path name.

[0106] S1321: Perform a query operation on the database based on the path name and file ID of the current path, and obtain a list of file objects under the current path returned by the database;

[0107] S1322: Determine whether the current path is the last level path in the second sub-path;

[0108] S1323: If so, then the list of file objects under the current path shall be used as the list of file objects under the second sub-path;

[0109] S1324: Otherwise, after replacing the next level path of the current path with the current path, return to the step of obtaining the path name of the current path from the two sub-paths and using the parent file ID obtained from the list of file objects queried under the previous level path as the file ID of the current path.

[0110] In this embodiment, when querying the second sub-path, the last level of the complete file path can be used as the first level of the second sub-path, and the file objects under the second sub-path can be obtained by querying from the last level upwards according to the path order between the levels of the second sub-path, thereby improving the efficiency of file query.

[0111] Specifically, this application can obtain the path name of the current path and the parent file ID obtained from the list of file objects retrieved from the previous level path as the file ID of the current path according to the path order between the various levels of the second sub-path. If the current path is the first level path, the file object list can be obtained by directly querying the database using the path name of the first level path. After obtaining the path name of the current path, a query operation can be performed on the database based on the path name and the file ID, and the file object list under the current path returned by the database can be obtained. Then, this application can determine whether the current path is the last level path in the second sub-path. If it is, the file object list under the current path can be used as the file object list under the second sub-path. If not, the next level path of the current path can be used as the current path, and the path name of the current path and the parent file ID obtained from the list of file objects retrieved from the previous level path can be obtained as the file ID of the current path. The database can be queried based on the path name and the file ID of the current path, and the file object list under the current path returned by the database can be obtained, until the current path is the last level path in the second sub-path.

[0112] For example, when the complete file path has n levels, and the second sub-path is from level m+1 to level n, this application can first obtain the path name of level n, and then query the current user's file records from the database. The query condition is files whose file names are the same as the path names of level n, resulting in a file object list a. The file IDs in file object list a are used as leaf node IDs and passed up the hierarchy for final matching of target files. Next, this application can obtain the parent file IDs (e.g., pfileId1, pfileId2) from file object list a, and query the database using the parent file IDs. The query condition is parent file ID pfileId1 or pfileId2, and files whose file names are the same as the path names of level n-1, resulting in a file object list b. The leaf node IDs are also passed to file object list b. This process continues until a file object list k at level m+1 is obtained, and this file object list k at level m+1 is used as the file object list under the second sub-path.

[0113] In one embodiment, the method may further include:

[0114] If the first file object found under any level of the first sub-path is empty, or if the list of file objects found under any level of the second sub-path is empty, then the query operation is stopped.

[0115] In this embodiment, if the first file object found in any path of the first sub-path is empty, or the list of file objects found in any path of the second sub-path is empty, it means that no relevant data can be matched in one of the sub-paths, and the query operation can be stopped at this time.

[0116] For example, this application can divide the path level n of the complete file path by 2 and round it to get m. Then, the path from level 1 to level m is placed into array 1 as the first sub-path, and the path from level m to level n is placed into array 2 as the second sub-path. At the same time, thread 1 is started to process the data in array 1, and thread 2 is started to process the data in array 2. When one of the threads cannot find the data in the database, it writes to the cache to execute the termination flag and terminates the thread; the other thread detects that there is a termination flag in the cache and terminates the thread.

[0117] In one embodiment, the first-level path in the second sub-path is the last-level path in the complete file path; S140, searching for the second file object corresponding to the first file object from the file object list and retrieving the target file from the database based on the second file object, may include:

[0118] S141: Obtain at least one parent file ID corresponding to the last path in the second sub-path from the file object list, and obtain the corresponding file ID from the first file object.

[0119] S142: Compare each parent file ID with the file ID, and take the file object corresponding to the parent file ID that is the same as the file ID as the file ID as the second file object. The second file object contains the file ID of the leaf node in the list of file objects queried from the first-level path of the second sub-path.

[0120] S143: Search the database for the file object corresponding to the file ID of the leaf node, and use the file object as the target file.

[0121] In this embodiment, after obtaining the first file object under the first sub-path and the list of file objects under the second sub-path, this application can search for the second file object corresponding to the first file object from the list of file objects, and obtain the target file from the database based on the second file object.

[0122] Specifically, this application can obtain at least one parent file ID corresponding to the last path in the second sub-path from the file object list, and obtain the corresponding file ID from the first file object. Then, each parent file ID is compared with the file ID, and the file object corresponding to the parent file ID that is the same as the file ID is taken as the second file object. The second file object contains the file ID of the leaf node in the file object list queried under the first-level path inherited from the second sub-path. Therefore, the file object corresponding to the file ID of the leaf node can be found in the database through the second file object, and the file object is taken as the target file.

[0123] In one specific implementation, this application can divide the path level n of the complete file path by 2 and round it to obtain m. Then, the paths from level 1 to m are placed into array 1 as the first sub-path, and the paths from level m to n are placed into array 2 as the second sub-path. Simultaneously, thread 1 is started to process the data in array 1, and thread 2 is started to process the data in array 2. Then, this application can obtain the file object list k and the corresponding parent file ID (e.g., fileIdm, fileIdm1, fileIdm2) from thread 2, and obtain the file object 1 and the corresponding file ID (e.g., fileIdm1, fileIdm2) from thread 1. After obtaining the parent file ID and the file ID, this application can traverse the list of file objects k and compare whether the parent file ID (e.g., fileIdm, fileIdm1, fileIdm2) of each file object is equal to the file ID (e.g., fileIdm) of file object 1. Through comparison, the file object 3 with the parent file ID fileIdm is finally found from the list of file objects k. The file object 3 records the file ID of the leaf node. Based on the file ID of the leaf node, the database is queried to obtain the file object, and finally the target file is obtained.

[0124] The following describes the file query device based on adjacency list provided in the embodiments of this application. The file query device based on adjacency list described below can be referred to in correspondence with the file query method based on adjacency list described above.

[0125] In one embodiment, such as Figure 3 As shown, Figure 3 This application provides a schematic diagram of a file query device based on an adjacency list, which may include a path acquisition module 210, a first query module 220, a second query module 230, and a file acquisition module 240, specifically including the following:

[0126] The path acquisition module 210 is used to acquire the complete file path corresponding to the target file to be queried, and to determine the path level of the complete file path.

[0127] The first query module 220 is used to obtain the target file by sequentially querying the paths in the complete file path according to the path order of each level if the path level is not greater than a preset level threshold.

[0128] The second query module 230 is used to split the complete file path into a first sub-path and a second sub-path if the path level is greater than the preset level threshold, and to query the first sub-path and the second sub-path respectively according to the preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path.

[0129] The file acquisition module 240 is used to search for a second file object corresponding to the first file object from the file object list, and to obtain the target file from the database based on the second file object.

[0130] In the above embodiments, when a user needs to query related files, the complete file path corresponding to the target file to be queried can be obtained first, and the path level of the complete file path can be determined. Then, the path level is judged. If the path level is not greater than a preset level threshold, the target file can be obtained by querying the path order between each level of the complete file path. If the path level is greater than the preset level threshold, it indicates that there are many path levels in the current complete file path. At this time, the complete file path can be split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path can be queried according to the preset file query rules respectively, and the first file object queried under the first sub-path and the list of file objects queried under the second sub-path can be obtained. Then, this application can find the second file object corresponding to the first file object from the list of file objects, and obtain the target file from the database based on the second file object. This process can be executed asynchronously and simultaneously, thereby effectively improving the query and positioning efficiency, reducing the file query time, and improving the user experience when there are many path levels in the complete file path.

[0131] In one embodiment, this application also provides a computer device, including: one or more processors, and memory.

[0132] The memory stores computer-readable instructions, which, when executed by the one or more processors, perform the steps of the file query method based on an adjacency list as described in any of the above embodiments.

[0133] Indicatively, such as Figure 4 As shown, Figure 4 This is a schematic diagram of the internal structure of a computer device 300 provided in an embodiment of this application. The computer device 300 can be provided as a server. (Refer to...) Figure 4 The computer device 300 includes a processing component 302, which further includes one or more processors, and memory resources represented by memory 301 for storing instructions, such as application programs, that can be executed by the processing component 302. The application programs stored in memory 301 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 302 is configured to execute instructions to perform the adjacency list-based file query method of any of the above embodiments.

[0134] The computer device 300 may also include a power supply component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate on an operating system stored in memory 301, such as Windows Server™, Mac OS X™, Unix™, Linux™, Free BSD™, or similar.

[0135] Those skilled in the art will understand that Figure 4 The 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.

[0136] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, 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 a process, method, article, or apparatus. Without further limitations, 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 said element.

[0137] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0138] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A file query method based on an adjacency list, characterized in that, The method includes: Obtain the complete file path corresponding to the target file to be queried, and determine the path hierarchy of the complete file path; If the path level is not greater than the preset level threshold, the target file is obtained by querying in the order of the paths between each level in the complete file path. If the path level is greater than the preset level threshold, the complete file path is split into a first sub-path and a second sub-path, and the first sub-path and the second sub-path are queried according to the preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path; the first sub-path contains the first-level path in the complete file path, and the first-level path in the second sub-path is the last-level path in the complete file path; The process includes: searching the list of file objects for a second file object corresponding to the first file object, and retrieving the target file from the database based on the second file object; Obtain at least one parent file ID corresponding to the last path in the second sub-path from the list of file objects, and obtain the corresponding file ID from the first file object; Each parent file ID is compared with the file ID, and the file object corresponding to the parent file ID that is the same as the file ID is taken as the second file object. The second file object contains the file ID of the leaf node in the list of file objects queried from the first-level path of the second sub-path. The database is searched for the file object corresponding to the file ID of the leaf node, and the file object is used as the target file.

2. The file query method based on adjacency list according to claim 1, characterized in that, The process of sequentially querying the paths within the complete file path to obtain the target file includes: According to the path order between the paths in the complete file path, obtain the path name of the current path from the complete file path and obtain the parent file ID of the current path from the file object queried from the previous path, wherein the parent file ID of the first path in the complete file path is empty; The database is queried based on the path name and parent file ID of the current path, and the file objects under the current path are returned by the database. Determine whether the current path is the last level path in the complete file path; If so, the file object under the current path will be used as the target file; Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the complete file path and obtaining the parent file ID of the current path from the file object queried from the previous level path.

3. The file query method based on adjacency list according to claim 2, characterized in that, Before determining whether the current path is the last level path in the complete file path, the method further includes: Determine whether the file object in the current path is empty; If the value is empty, the query operation will stop. If it is not empty, then the step of determining whether the current path is the last level path in the complete path of the file is executed.

4. The file query method based on adjacency list according to claim 1, characterized in that, The process involves querying the first subpath and the second subpath according to preset file query rules to obtain a list of first file objects under the first subpath and a list of file objects under the second subpath, including: Using the first-level path in the complete file path as the first-level path in the first sub-path, the first file object under the first sub-path is obtained by sequentially querying according to the path order between each level of the first sub-path. Using the last level of the complete file path as the first level of the second sub-path, and querying sequentially from the last level upwards according to the path order of each level of the second sub-path, a list of file objects under the second sub-path is obtained.

5. The file query method based on adjacency list according to claim 4, characterized in that, The process of sequentially querying the paths in the first sub-path to obtain the first file object under the first sub-path includes: According to the path order between the paths in the first sub-path, the path name of the current path is obtained from the first sub-path and the parent file ID of the current path is obtained from the file object queried from the previous path. The parent file ID of the first path in the first sub-path is empty. The database is queried based on the path name and parent file ID of the current path, and the file objects under the current path are returned by the database. Determine whether the current path is the last level path in the first sub-path; If so, the file object under the current path is taken as the first file object under the first subpath; Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the first sub-path and obtaining the parent file ID of the current path from the file object queried from the previous level path.

6. The file query method based on adjacency list according to claim 4, characterized in that, The process of querying from the last level upwards according to the path order of each level in the second sub-path to obtain the list of file objects under the second sub-path includes: According to the path order between the paths in the second sub-path, the path name of the current path is obtained from the second sub-path, and the parent file ID obtained from the list of file objects queried under the previous path is used as the file ID of the current path. The first path in the second sub-path is the list of file objects obtained by querying the database using its path name. The database is queried based on the path name and file ID of the current path, and a list of file objects under the current path is returned by the database. Determine whether the current path is the last level path in the second sub-path; If so, the list of file objects under the current path will be used as the list of file objects under the second subpath; Otherwise, after replacing the next level path of the current path with the current path, return to the steps of obtaining the path name of the current path from the second sub-path and using the parent file ID obtained from the list of file objects queried under the previous level path as the file ID of the current path.

7. The file query method based on adjacency list according to claim 4, characterized in that, The method further includes: If the first file object found under any level of the first sub-path is empty, or if the list of file objects found under any level of the second sub-path is empty, then the query operation is stopped.

8. A file query device based on an adjacency list, characterized in that, include: The path acquisition module is used to obtain the complete file path corresponding to the target file to be queried, and to determine the path level of the complete file path; The first query module is used to obtain the target file by sequentially querying the paths in the complete file path according to the path order between each level if the path level is not greater than a preset level threshold. The second query module is used to split the complete file path into a first sub-path and a second sub-path if the path level is greater than the preset level threshold, and to query the first sub-path and the second sub-path respectively according to the preset file query rules to obtain a list of first file objects under the first sub-path and a list of file objects under the second sub-path; the first-level path in the second sub-path is the last-level path in the complete file path; The file acquisition module is used to search for a second file object corresponding to the first file object from the file object list, and to retrieve the target file from the database based on the second file object, including: Obtain at least one parent file ID corresponding to the last path in the second sub-path from the list of file objects, and obtain the corresponding file ID from the first file object; Each parent file ID is compared with the file ID, and the file object corresponding to the parent file ID that is the same as the file ID is taken as the second file object. The second file object contains the file ID of the leaf node in the list of file objects queried from the first-level path of the second sub-path. The database is searched for the file object corresponding to the file ID of the leaf node, and the file object is used as the target file.

9. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions that, when executed by the one or more processors, perform the steps of the file query method based on an adjacency list as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Path query method and device, electronic equipment and computer-readable storage medium

    CN112000695A