A network layer optimization method, related device, equipment and storage medium
By optimizing the network layer design of the file management application, defining protocol buffer files and serialization functions, and eliminating unused code, the problems of network layer redundancy and initialization time consumption were solved, thereby improving system performance and development efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2025-01-02
- Publication Date
- 2026-07-03
AI Technical Summary
Existing file management applications suffer from problems such as code redundancy, long initialization time, and complex nested parameter formatting in their network layer design, which affect system performance and development efficiency.
By defining the parameter structure and type in the protocol buffer file, a target serialization function is created, a network layer request service is constructed, and unused code is eliminated through a code optimization mechanism to optimize the code of the network layer request service.
It achieves clear code structure and well-defined responsibilities, reduces code size, improves system initialization speed and memory utilization, enhances code quality and maintainability, and improves system performance and development efficiency.
Smart Images

Figure CN122339969A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for optimizing a network layer. Background Technology
[0002] With the continuous development of internet technology, various enterprise-level applications are emerging in the office field, among which file management applications play an important role. However, existing technologies have certain problems in the network layer design of file management applications.
[0003] Traditional network layer designs typically retrieve a specific description file (e.g., a proto file) from the backend when handling data interactions. Based on this file, they then generate standardized classes for network request functions and request data related to each Common Gateway Interface (CGI). These generated request functions and data classes are dynamically attached to a global object using specific methods (such as computed property names). When business code needs to interact with data, it calls the classes and methods on this global object to create a standard serialization function body and initiate the CGI request.
[0004] However, this traditional design has many drawbacks. First, the automatically generated CGI code often contains a large number of redundant interface functions. These unnecessary functions not only increase code complexity but also make code maintenance difficult. Second, the large number of related backend description files and their complex dependencies result in a massive generated CGI code size. In practical applications, clients often only need a portion of the functionality, but due to the global object design, the client has to import the entire network layer code during initialization. This makes loading RequireJS during initialization time-consuming, impacting system startup speed and overall performance. Furthermore, for nested parameters of array or object types, the business code needs to manually call classes to create objects and perform formatting operations. When encountering numerous nested serialization functions, this generates a large amount of code that manually calls formatting parameters, which is not only tedious but also error-prone, reducing development efficiency.
[0005] In summary, the existing network layer design of file management applications has shortcomings in terms of code efficiency, performance optimization, and ease of development. Optimization of the network layer of file management applications is needed to solve these problems. Summary of the Invention
[0006] This application provides a method, related apparatus, device, and storage medium for optimizing the network layer, thereby solving the problems of large code size, time-consuming initialization, and complex formatting of nested parameters.
[0007] This application provides a method for optimizing a network layer, including:
[0008] Define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file; wherein, the parameter type is used to characterize the data type, and the parameter structure is used to characterize the data unit composed of at least two parameter types;
[0009] Create a target serialization function based on the target protocol buffer file;
[0010] Based on the target protocol buffer file and the target serialization function, a network layer request service is constructed.
[0011] By using code optimization mechanisms, unused code in the network layer request service code is removed to obtain the target code for the network layer request service.
[0012] Based on the target code for network layer request services, the code responsible for managing related business in the network layer of the file management application is constructed.
[0013] This application also provides a network layer optimization apparatus.
[0014] The definition module is used to define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file; wherein, the parameter type is used to characterize the data type, and the parameter structure is used to characterize the data unit composed of at least two parameter types;
[0015] Create a module to create a target serialization function based on the target protocol buffer file;
[0016] The building module is used to construct network layer request services based on the target protocol buffer file and the target serialization function;
[0017] The optimization module is used to remove unused code from the code that requests services at the network layer through a code optimization mechanism, thereby obtaining the target code for the network layer request services.
[0018] The build module is also used to build the code responsible for managing related business in the network layer of the file management application based on the target code for requesting services at the network layer.
[0019] In another aspect, this application provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the methods described above.
[0020] Another aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods described above.
[0021] Another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the methods described above.
[0022] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0023] This application provides a network layer optimization method. First, by defining the parameter structure and parameter types in a protocol buffer file (such as a proto file), the entire network layer code becomes structurally clearer, and the responsibilities and functions of each part are easier to understand. Second, using the obtained target protocol buffer file, a target serialization function is created. This function can convert the data of the business layer according to the structure and type defined in the proto file, enabling it to be accurately transmitted over the network or correctly stored in the storage medium. Next, the constructed network layer request service integrates the cgiUrl, parameter serialization function, and request function, providing a unified interface for the business layer to initiate network requests. Then, through code optimization mechanisms, eliminating unused code can significantly reduce the code size of the network layer request service, thereby accelerating the code process initialization. Simultaneously, during runtime, a smaller code size also consumes less memory resources, allowing the system to allocate more memory to processing actual business data. Finally, the code construction responsible for managing related business in the network layer of the file management application is closely integrated with the optimization of the network layer request service. By using the optimized target code of the network layer request service, the business code can more concisely and efficiently implement the file management-related business logic. In summary, the optimization method provided in this application improves code quality and maintainability, enhances code flexibility and scalability, and improves system performance and efficiency. Attached Figure Description
[0024] Figure 1 The network layer optimization method provided in this application is applied to an online document collaboration platform, as shown in the scenario architecture diagram.
[0025] Figure 2 A flowchart illustrating the network layer optimization method provided in this application embodiment;
[0026] Figure 3 Technical architecture diagram of the network layer optimization method provided in the embodiments of this application;
[0027] Figure 4 A comparison diagram of the network layer before and after reconstruction provided in the embodiments of this application;
[0028] Figure 5 A flowchart illustrating the invocation process of a single network layer service API provided in this application embodiment;
[0029] Figure 6 This is a structural diagram of the network layer optimization device provided in an embodiment of this application. Detailed Implementation
[0030] This application provides a method for optimizing a network layer, which improves code quality, performance, and flexibility by optimizing the design of the network layer.
[0031] 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 of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0033] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0034] Before introducing the specific methods of this application, we will first provide an illustrative example of the application scenarios for network layer optimization in this application. It should be understood that the following application scenarios are merely illustrative and are not limited to these examples.
[0035] The network layer optimization method provided in this application embodiment can be applied to online document collaboration platforms.
[0036] First, define the relevant content of the proto file. In online document collaboration platforms, operations such as document creation, editing, saving, and sharing require defining the parameter structure (e.g., message) and parameter types (e.g., enum) in the protocol buffer file. For example, in document creation, the message structure can define fields such as document title (string type), author (string type), and creation time (which may be a specific time type and needs to be converted to an appropriate format for subsequent processing) as specific interface forms, clearly defining the data type and structural relationship of each field. For enumeration types (enum) representing document permissions (e.g., read-only, editable, commentable, etc.), define them as a combination of interface and constant variables to uniformly manage and identify document permission status throughout the system. In this way, developers can clearly understand the data structures involved in document operations, providing a solid foundation for subsequent development work and ensuring that different modules follow a unified standard when processing document data.
[0037] Secondly, create the target serialization function. Based on the defined proto file, create the target serialization function for document collaboration operations. Taking document saving as an example, when creating the initial request parameters, it includes multiple fields such as document content (which may be a complex nested structure containing text, formatting, image references, etc.) and the current document version number (which may be an integer type, requiring consideration of range and precision), each with a default value. When the user clicks to save the document, the actual content in the document editing area and the system-generated current version number are retrieved, and the initial request parameters are assigned values. If certain data types in the document content (such as data types representing large file sizes or complex formats, like uint64), they need to be converted to appropriate types (such as BigNumber type or other types specifically designed for handling document data) to ensure data accuracy and integrity. For nested types, such as image references in the document content which may contain nested information such as image IDs and image positions in the document (similar to the xmdiskacctcomm.DocTopInfo structure), the corresponding formatting function is called to format the data, ultimately obtaining a target serialization function suitable for network transmission. This ensures that the document data can be accurately serialized into a transmittable format for saving and subsequent processing on the server side.
[0038] Next, the network layer request service is constructed. The common gateway interface (cgiUrl) is determined; for example, the cgiUrl of the document saving service points to the document saving interface address of the online document collaboration platform server. Then, based on the parameter structure and type in the proto file and the target serialization function, a parameter serialization function is constructed. This function is responsible for converting the document collaboration operation parameters provided by the business layer (such as document content, version number, etc. when saving the document) into a format that conforms to the cgiUrl requirements. Next, the request function is constructed. In the document saving scenario, the retry mechanism set within the request function can automatically retry when saving fails due to network instability, improving the success rate of saving and preventing users from losing edited content due to network problems. The request cancellation mechanism allows users to cancel operations during the saving process; for example, if a user finds a problem with the document being saved or does not want to save the current changes, they can cancel in time to avoid unnecessary resource consumption. The automatic serialization mechanism ensures that parameters are correctly serialized, guaranteeing that document data can be accurately sent to the server. Finally, a complete network layer request service is built based on cgiUrl, parameter serialization function, and request function, enabling the business layer to easily initiate document save requests and other document collaboration-related requests (such as creation, editing, sharing, etc.).
[0039] Next, code optimization and business code construction are performed. Through code optimization mechanisms, unused code in the network layer request service code is removed, resulting in optimized target code. In online document collaboration platforms, for example, some code related to document operations used for specific testing functions or that has been deprecated is removed, reducing code size and improving system efficiency and maintainability. For online document collaboration business code originally based on a certain programming language (such as JavaScript), it is converted to TypeScript code, resulting in target language code. In document sharing, the target language code calls the network layer request service, and the network layer performs nested processing based on sharing parameters (such as the sharing object, sharing permissions, etc.), resulting in parameter assignment code. Furthermore, a lazy loading mechanism is adopted, loading the relevant sharing module code only when the user clicks the share document button for the first time, improving the platform's initialization speed and optimizing the user experience, especially when the user uses the platform for the first time or returns after a long period of inactivity, allowing for faster access to an operational state.
[0040] Finally, network requests and data interaction occur. When a user performs document operations (such as opening and editing a document) on the online document collaboration platform, the terminal obtains the application programming interface (API) corresponding to the network layer request service and initial request data (such as document ID, user identity information, etc.). Based on the API and initial request data, the terminal calls the request function corresponding to the network layer request service. The request function formats the initial request data (such as converting user identity information into a server-verifiable format and document ID into a server-recognizable document index) to obtain the target request data, and then sends the target request data to the server through the Common Gateway Interface (CGI). The server processes the received target request data (such as finding document content based on document ID, and returning corresponding document editing interface data based on user authentication permissions), obtains initial return data (containing document content, editing permission information, etc.), and sends it back to the terminal. After receiving the initial return data, the terminal parses its format (such as converting the document data returned by the server into a platform-editable document format and converting permission information into prompts or restrictions that can be displayed on the interface), obtains the target return data, and finally displays it to the user in the editing interface of the online document collaboration platform, allowing the user to perform document editing operations.
[0041] Please see Figure 1 , Figure 1 The diagram illustrates a scenario architecture diagram of the network layer optimization method provided in this application embodiment applied to an online document collaboration platform. Among them,
[0042] Terminal 110 includes a human-computer interaction screen, a processor, and a memory. The human-computer interaction screen is used to display an online document collaboration platform and also to provide a human-computer interaction interface to receive information input by the user. The processor is used to generate interaction instructions in response to the above human-computer interaction operations and send the interaction instructions to the server. The memory is used to store relevant attribute data.
[0043] The terminal 110 involved in this application includes, but is not limited to, mobile phones, tablets, laptops, desktop computers, smart voice interaction devices, virtual reality devices, smart home appliances, vehicle terminals, aircraft, etc.
[0044] Run client 1101 on terminal 110. Taking the client of an online document collaboration platform as an example, client 1101 is deployed on terminal 110. Client 1101 can run on terminal 110 through a browser, or as a standalone application (APP) or mini-program, etc.
[0045] Network 120 uses standard communication technologies and / or protocols, typically the Internet, but can also be any network, including but not limited to Bluetooth, local area network (LAN), metropolitan area network (MAN), wide area network (WAN), mobile, private network, or any combination of virtual private network. In some embodiments, custom or dedicated data communication technologies may be used to replace or supplement the aforementioned data communication technologies.
[0046] Server 130 includes a processor. The server 130 involved in this application can be a standalone physical server, a server cluster or distributed system consisting of at least one physical server, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence (AI) platforms.
[0047] As in step S101, in the terminal, the parameter structure and parameter type in the protocol buffer file are defined to obtain the target protocol buffer file; wherein, the parameter type is used to characterize the type of data, and the parameter structure is used to characterize a data unit composed of at least two parameter types.
[0048] As in step S102, the terminal creates a target serialization function based on the target protocol buffer file;
[0049] As in step S103, the terminal constructs a network layer request service based on the target protocol buffer file and the target serialization function;
[0050] As in step S104, the terminal uses a code optimization mechanism to remove unused code from the code that requests services at the network layer, thereby obtaining the target code for the network layer service request.
[0051] As in step S105, the terminal constructs the code responsible for managing related business in the network layer of the file management application based on the target code for requesting services at the network layer.
[0052] The optimization method provided in this application improves code quality and maintainability, enhances code flexibility and scalability, and improves system performance and efficiency.
[0053] Please see Figure 2 , Figure 2A flowchart of a network layer optimization method is shown. It should be noted that the network layer optimization method provided in this application embodiment can be applied to a terminal, and this application embodiment does not impose any limitations. The method includes:
[0054] S210. Define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file.
[0055] Among them, parameter type is used to characterize the type of data, and parameter structure is used to characterize a data unit composed of at least two parameter types.
[0056] Understandably, in the specific implementation process, it is first necessary to analyze the business scenarios involved, such as the various operational requirements in application scenarios like file management and data interaction. For file management scenarios, to implement functions such as uploading, downloading, deleting, and sharing files, it is necessary to clarify the data structures involved in these operations.
[0057] Taking file upload as an example, when defining the parameter structure in the protocol buffer file (proto file), basic file attributes, such as filename, can be defined as string type, using its TypeScript interface. For file size, if a large value is involved, it may need to be defined as an appropriate type (such as uint64, which will be handled specially in the serialization function). File type is also defined as string. These fields together form the parameter structure (message) of the file upload operation, clearly defining the data structure to be transmitted during file upload.
[0058] For enumeration types in parameter types, such as file sharing permissions, there may be states like read-only (READ_ONLY), editable (EDITABLE), and shareable (SHAREABLE). In TypeScript, this is defined as a combination of an interface and a constant variable.
[0059] This definition allows for clear identification and processing of file sharing permission-related data throughout the system, ensuring that different modules adhere to a unified standard when handling file permissions. After detailed definition of the parameter structure and types for all related operations, the target protocol buffer file is ultimately obtained, laying a solid data structure foundation for subsequent operations.
[0060] S220. Based on the target protocol buffer file, create the target serialization function.
[0061] Understandably, based on the previously defined target protocol buffer file, the target serialization function is created. Taking a file upload scenario as an example, initial request parameters are first created based on the parameter structure (message) in the protocol buffer file (proto file). Assuming the file upload message structure (message) contains fields such as filename, file size, and file type mentioned above, default values will be assigned to each field when creating the initial request parameters.
[0062] After the user selects a file to upload, the system retrieves the file's actual information, including the filename, file size, and file type. It then assigns these values to the initial request parameters, resulting in the assigned request parameters. Next, specific fields in the assigned request parameters undergo type conversion. For example, the file size field (assuming a uint64 type) needs to be converted to a type suitable for handling large numbers, such as BigNumber. For nested fields, such as metadata that the file may contain (similar to the xmdiskacctcomm.DocTopInfo structure, assuming it contains nested information like file creation time and modification time), the corresponding formatting function needs to be called for formatting. After these operations of field assignment, type conversion, and nested type formatting, the final complete target serialization function is obtained. This function converts the file upload request parameters into a format suitable for network transmission, ensuring the accuracy and integrity of file-related data in the network request.
[0063] S230. Based on the target protocol buffer file and the target serialization function, construct the network layer request service.
[0064] Understandably, the first step in building a network layer request service is to obtain the generic gateway interface (cgiUrl). Different operations in a file management application, such as file upload, download, and deletion, each have a corresponding cgiUrl. For example, the cgiUrl of the file upload service points to the server-side interface address specifically used to receive file upload requests, let's say it's https: / / example.com / upload.
[0065] Based on the parameter structure (message) and parameter types (enum) in the protocol buffer file (proto file), and the previously created target serialization function, a parameter serialization function is constructed. The main function of this function is to convert the file management operation parameters provided by the business layer (such as request parameters when uploading files) according to the format required by cgiUrl. For example, converting the file upload request parameter uploadParamsAfterFormatting into a format that conforms to the requirements of the https: / / example.com / upload interface might involve serializing it into a JSON string or other specific data format so that it can be accurately sent to the server.
[0066] Next, we construct the request function. In the file upload scenario, the request function sets up several important mechanisms:
[0067] The retry mechanism sets a maximum number of retries (e.g., 3 times) and retry intervals (e.g., 1 second for the first retry, 2 seconds for the second, and 3 seconds for the third). When network instability causes file upload failure, it automatically re-initiates the request according to the set rules. For example, if the first upload fails due to network interruption, the request function will wait 1 second before attempting a second attempt. If that also fails, it will wait 2 seconds before attempting a third attempt, thereby improving the success rate of file uploads and avoiding frequent manual retries by users due to network issues.
[0068] The cancellation request mechanism allows users to cancel the file upload operation at any time. For example, if a user discovers they have selected the wrong file or no longer wish to continue uploading a large file, they can trigger the cancellation request mechanism by clicking the cancel button. The request function will respond promptly and stop the upload operation, releasing relevant resources and avoiding waste. The automatic serialization mechanism ensures that the parameters provided by the business layer are correctly serialized into a network-transmittable format, guaranteeing that the file upload request is sent to the server accurately.
[0069] Finally, based on the obtained general gateway interface (cgiUrl), the constructed parameter serialization function, and the request function, they are integrated to build a complete network layer request service. In this way, when the business layer needs to perform a file upload operation, it only needs to call this network layer request service to complete a series of operations from parameter preparation and serialization to request sending, greatly simplifying the interaction between the business layer and the network layer, improving development efficiency and system reliability.
[0070] S240. Through code optimization mechanisms, unused code in the network layer request service code is removed to obtain the target code for the network layer request service.
[0071] Understandably, after the initial construction of the network layer request service is completed, code optimization mechanisms are needed to improve system performance and reduce code size. In practical applications, there may be some code that is not used in specific business scenarios. For example, in a file management application, if a specific file format conversion function is no longer used in the current version, but related code was left over from previous development, this code is considered unused.
[0072] Code analysis tools (such as the tree-shaking functionality provided by build tools like Webpack) are used to scan the code for network layer request services. This tool retrieves reference relationships within the code, identifying which code modules or functions are not called or referenced throughout the business process. Unused code is removed from the final codebase. For example, the aforementioned unused file format conversion function-related code was determined to be unused during the analysis, and therefore will not be included when generating the target code for network layer request services.
[0073] After code optimization, the target code for network layer request services is smaller, reducing the amount of code that needs to be loaded during system startup and thus speeding up the initialization of the Node process. During runtime, the smaller code size also consumes less memory resources, allowing the system to allocate more resources to handling actual business logic, such as file data transfer, storage, and processing, thereby improving the overall performance and response speed of the system.
[0074] S250, Based on the target code for network layer request services, construct the code responsible for managing related business in the network layer of the file management application.
[0075] Understandably, the JavaScript-based network layer code responsible for managing related business logic in a file management application first needs to be converted to TypeScript. During this conversion, TypeScript syntax must be followed, including explicit declaration of variable types and type annotations for function parameters and return values. Based on the converted target language code, the previously constructed network layer requests services. In the file download business logic, when a user clicks the download button, the business layer code prepares the necessary parameters for downloading (such as the file's URL and download path) and then calls the network layer to request services. The network layer performs nested processing based on these parameters, such as serializing and formatting the download parameters according to the network layer's request service requirements, to obtain the parameter assignment code.
[0076] Finally, the parameter-assigning code is called according to the lazy import mechanism. When the file management application starts, not all file management business module code is loaded immediately. Instead, the corresponding download module code is loaded only when the user performs a related operation for the first time (such as clicking the download file button for the first time). This improves the initialization speed of the Node process, avoids loading a large amount of unnecessary code at startup, and optimizes the system's resource utilization efficiency and startup performance. When the user performs the same operation again, since the code has already been loaded, it can quickly respond to user requests, improving the user experience. The method provided in this application improves code quality and maintainability through clearly defined data structures and standardized code format; improves system performance and efficiency, such as optimizing network request processing, reducing code size and resource consumption; and enhances code flexibility and scalability, facilitating functional expansion, adjustment, and support for the integration of multiple business scenarios.
[0077] The method provided in this application improves code quality and maintainability by clearly defining data structures and standardizing code format; enhances system performance and efficiency, such as optimizing network request processing, reducing code size and resource consumption; and strengthens code flexibility and scalability, facilitating functional expansion, adjustment, and support for the integration of multiple business scenarios.
[0078] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, the parameter structure includes a message structure, the parameter type includes an enumeration type, and the parameter structure and parameter type are defined in the protocol buffer file, including:
[0079] Define the message structure in the protocol buffer file as an interface in the TypeScript language. The interface is used to define the structure of an object, the signature of a function, or the contract that a class needs to follow.
[0080] Define the enumeration types in the protocol buffer file as a combination of interfaces and constant variables in the TypeScript language, where constant variables are used to represent variables with fixed values.
[0081] Understandably, in practical applications, when various business operations are involved (such as file operations in file management, data interaction in online collaboration, etc.), it is necessary to clearly define the structure and organization of data. Taking file upload operations in file management as an example, suppose a file upload needs to include information such as filename, file size, and file type, defined in the protocol buffer file (proto file) as a message structure. To better handle this data in the TypeScript environment, the above message structure is defined as an interface in the TypeScript language. The advantage of defining an interface in this way is that it clearly specifies the data structure involved in the file upload operation. In the business code, when processing file upload requests, developers can define variables, function parameters, and return values based on this interface. For example, in a file upload service class, there might be a function to receive file upload parameters, and its parameter type could be defined as the FileUploadMessage interface type. This approach makes the data processing throughout the file upload process more standardized and easier to understand. Different developers can work based on this unified interface definition when writing code related to file uploads, improving code readability and maintainability. At the same time, it makes it easier to check the correctness and integrity of data during code review or debugging, because the interface clearly defines the structure and type that the data should have.
[0082] Suppose a file has different permission states, such as read-only (READ_ONLY), editable (EDITABLE), and shareable (SHAREABLE), and an enumeration type is defined in the proto file. In TypeScript, this is defined as a combination of an interface and constant variables. First, the interface is defined, and then the constant variables are defined. In actual business code, when file permission-related operations need to be handled, this definition method provides a clear representation of permission states. For example, in a file access control function, different operations can be performed based on the file's permission state. This definition method makes file permission handling more intuitive and secure. The interface provides type constraints on the permission state, ensuring the correctness of passing and using permission values in the code. The constant variables provide specific permission values, facilitating comparison and judgment in the code. At the same time, this combination method also facilitates unified management and expansion of file permission-related functions in the system. If new permission states need to be added in the future, only corresponding extensions need to be made to the interface and constant variables, without affecting the existing permission handling logic in the code, improving the system's scalability and flexibility. In other business scenarios, such as user permission management in online document collaboration, a similar approach can be used to define and handle enumeration types to ensure consistency and standardization in the handling of enumeration types across different functional modules of the system.
[0083] The method provided in this application improves code standardization and readability by defining the message structure in the proto file as a TypeScript interface, clarifying the data structure, and making it easier for developers to understand and follow a unified standard. It also enhances the security and scalability of data processing by defining enumeration types as interfaces and combining them with constant variables, which facilitates the management, comparison, and judgment of enumeration values such as permissions, and is conducive to the expansion of system functions. At the same time, it ensures the consistency of data processing in different scenarios.
[0084] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, a target serialization function is created based on the target protocol buffer file, including:
[0085] Based on the parameter structure in the protocol buffer file, an initial request parameter is created. The initial request parameter contains M fields, and each field corresponds to a default value. M is an integer greater than or equal to 1.
[0086] Get the parameter values corresponding to M fields, and assign values to the initial request parameters according to the parameter values corresponding to M fields to obtain the assigned request parameters;
[0087] Convert the field types of K target fields out of M fields in the assignment request parameters to obtain the target request parameters, where K is an integer greater than or equal to 1 and less than or equal to M;
[0088] The parameter types of the target request parameters are formatted to obtain the target serialization function.
[0089] Understandably, in specific application scenarios, such as file upload operations in file management applications, the initial request parameters must first be created based on the parameter structure (message) defined in the proto file. Assuming the file upload message structure (message) includes fields such as filename (string type), file size (uint64 type), and file type (string type), when creating the initial request parameters, default values will be assigned to each field according to their definitions.
[0090] For other business scenarios, such as document saving operations in online document collaboration, if the document saving message structure includes fields such as document title (string type), document content (which may be a complex nested type), and document version number (integer type), default values will also be assigned to these fields when creating the initial request parameters. The purpose of creating these initial request parameters in this way is to provide a basic framework for subsequently obtaining and assigning actual parameter values, ensuring the structural integrity of the request parameters, and setting default values can avoid errors caused by not obtaining actual values in certain situations.
[0091] Taking file upload as an example, after a user selects a file to upload in the file management application, the system obtains the actual information of the file through appropriate methods, including parameter values such as file name, file size, and file type. Assuming the user selects a file named "example.txt", with a size of 1024 bytes and a file type of "text / plain", these parameter values are obtained and then assigned to the initial request parameters.
[0092] In online document collaboration scenarios, when a user finishes editing a document and clicks save, the system retrieves parameter values from the document editing area, such as the title (e.g., "Project Report"), the document content (including text content and formatting information), and the automatically updated document version number (e.g., 2). These values are then used to assign values to the initial save request parameters. This method uses actual parameter values to override the default values of the initial request parameters, ensuring that the assigned request parameters accurately reflect the user's operational intent or the actual situation of the business data, thus providing accurate data preparation for subsequent network requests.
[0093] For file upload scenarios, the file size field (assuming it is of type uint64) needs to be converted to the BigNumber type, which is more suitable for handling large numbers, since it may represent a large range of values (assuming there is already a corresponding conversion method toBigNumber).
[0094] In other business scenarios that may involve similar type conversions, such as when processing large integer data stored in a database, the same approach can be used for type conversion. For example, in a data statistics application, if the numeric field of a statistical result is of type uint64, it can be converted to BigNumber type before sending the statistical data via network request. This ensures the accuracy of the data during transmission and processing, and avoids data errors caused by insufficient type representation range.
[0095] Taking the metadata that a file in a file management application may contain (assuming it is a structure similar to xmdiskacctcomm.DocTopInfo, containing nested information such as file creation time and modification time) as an example, if we want to format it, let's assume there is a function formatFileMetadata for formatting file metadata.
[0096] In online document collaboration scenarios, if the document content contains complex nested structures, such as image references (including image IDs, image positions within the document, etc.), and there is a corresponding formatting function `formatImageReferences`, the nested types, such as image references, will be processed during the document saving parameters. This ensures the correct format of the entire document data before serialization, enabling accurate network transmission and server-side processing. Ultimately, after this series of operations, the resulting target serialization function can convert business data into a format suitable for network transmission, guaranteeing the accuracy and integrity of the data during network requests.
[0097] The method provided in this application ensures the accuracy of request parameters by creating initial request parameters, assigning values, and converting types to make the parameters conform to the actual business situation, avoiding errors caused by default values or type issues; it improves the adaptability of data processing, can handle complex data structures by formatting nested types, and ensures the integrity of data during network transmission and processing; it enhances the overall performance of the system, as accurate request parameters help network requests proceed smoothly, reduce errors caused by parameter issues, improve system stability and reliability, and also provide convenience for system maintenance and expansion.
[0098] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, the target field is an unsigned 64-bit integer field, and the parameter type of the initial serialization function is a nested type;
[0099] Convert the data types of K target fields out of the M fields in the assignment request parameters to obtain the target request parameters, including:
[0100] Convert the type of the K target fields in the assignment request parameters to a large number type to obtain the target request parameters.
[0101] The parameter types of the target request parameters are converted to obtain the target serialization function, including:
[0102] Call the nested formatting function to format the parameter types of the target request parameters, and obtain the target serialization function.
[0103] Understandably, in practical applications, when dealing with data that may exceed the range of conventional numeric types—such as file size records in file management applications or large numerical statistical results in data statistics applications—accurate conversion of specific field types is necessary. Taking file upload operations in a file management application as an example, suppose the file size field in the file upload message structure is defined as a type similar to uint64 (the actual definition may vary depending on the specific protocol and buffer file definition).
[0104] During the creation of the target serialization function, after obtaining the file size parameter value (e.g., 1024 bytes), it needs to be converted to the BigNumber type to ensure data accuracy and integrity. Assume a utility function `toBigNumber` already exists to perform this conversion (the implementation of this function may involve specific algorithms or libraries to handle the representation and operation of large numbers). Here, `toBigNumber(1024)` converts the integer 1024 to the BigNumber type, and then explicitly specifies the converted type through the type assertion `as BigNumber`, ensuring that the data in this field is treated correctly in subsequent processing. This conversion operation guarantees that when processing large files or involving large amounts of data storage and transmission, data such as file size will not result in errors due to exceeding the representation range of conventional numeric types. For example, it avoids erroneous results caused by data overflow when calculating the total file size or allocating disk space.
[0105] Taking the metadata that a file might contain in a file management application as an example, suppose the metadata has a structure similar to xmdiskacctcomm.DocTopInfo, containing nested information such as file creation time and modification time. When performing operations on the file (such as uploading, downloading, updating metadata, etc.), it is necessary to format these nested parameters to ensure that they meet the requirements of network transmission and server-side processing.
[0106] Suppose there exists a formatting function named `formatFileMetadata`, whose function is to convert file metadata into a specific format (e.g., converting a date format to a server-recognizable string, sorting fields in nested structures, or adding necessary identifiers, etc.). First, a file metadata object `fileMetadata` containing the file's creation and modification times is created. Then, the `formatFileMetadata` function is called to format the metadata, and the formatted result is assigned to the `metadata` field in the file upload parameters. In this way, when making network requests, the file metadata will be sent to the server in the correct format, and the server can accurately parse and process this metadata.
[0107] In other potential application scenarios, such as online document collaboration platforms, document content may contain complex nested structures, such as image references (including image IDs, image positions within the document, etc.). If corresponding formatting functions (such as `formatImageReferences`) exist, similar formatting processing will be applied to nested types like image references when saving or sharing the document. This ensures the consistency and correctness of the entire document data during network transmission and server-side processing, avoiding data parsing errors or functional abnormalities caused by incorrect nested structure formats.
[0108] The method provided in this application ensures data accuracy by converting uint64 type to BigNumber type to avoid data overflow or precision loss, and accurately processes large numerical data; it guarantees the integrity of complex data structures by formatting nested types so that the system can correctly process and transmit complex data, such as file metadata and nested information in document content; it enhances system stability by reducing errors caused by data type and structure problems, improving the reliability of the system in processing various complex data, and ensuring the smooth operation of business.
[0109] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, a network layer request service is constructed based on the target protocol buffer file and the target serialization function, including:
[0110] Obtain the general gateway interface;
[0111] Based on the parameter structure and parameter types in the protocol buffer file, and the target serialization function, construct the parameter serialization function;
[0112] Based on the general gateway interface and parameter serialization function, a request function is constructed, which includes a retry mechanism, a request cancellation mechanism, and an automatic serialization mechanism.
[0113] Based on the general gateway interface, parameter serialization function, and request function, construct the network layer request service.
[0114] Understandably, in specific application scenarios, different business operations correspond to different general gateway interfaces (cgiUrl). Taking a file management application as an example, for a file upload operation, it is necessary to determine its corresponding cgiUrl, which points to the interface address on the server side specifically used to receive file upload requests. Assuming the file upload service is deployed under the domain https: / / example.com, and its file upload interface path is / upload, then the cgiUrl for the file upload operation is https: / / example.com / upload.
[0115] During development, these cgiUrls are typically configured in a separate configuration file for easier management and maintenance. For example, in a Node.js-based project, there might be a `config.js` file containing cgiUrl configurations for various business operations. When a file upload operation is needed, the corresponding cgiUrl is obtained by referencing this configuration file in the network layer request service. This configuration method makes cgiUrl management more centralized and flexible. When the server-side interface address changes, only the corresponding cgiUrl value needs to be modified in the configuration file, rather than searching and modifying it one by one in a large amount of business code, thus improving system maintainability. Furthermore, different cgiUrls can be configured to easily switch interface addresses for different environments (such as development, testing, and production environments), ensuring the system functions correctly in different environments.
[0116] Based on the file upload message structure (message) in the previously defined protocol buffer file (proto file), such as fields including filename (string type), file size (BigNumber type after type conversion), file type (string type), and parameter type (enum, such as file permission type), and combined with the created target serialization function, the parameter serialization function is constructed.
[0117] The main function of this parameter serialization function is to convert the parameters of the file upload operation provided by the business layer (such as the file information selected by the user, the file permissions set, etc.) into the format required by the server-side cgiUrl. Assuming the server requires the file upload parameters to be sent in JSON format, the parameter serialization function will serialize the object containing the file information and permission information into a JSON string. First, it constructs an object `serializedParams` containing all relevant information based on the passed file upload parameter `params`, and then uses the `JSON.stringify` method to convert it into a JSON string. During the construction process, appropriate processing is performed for different types of fields (such as the file size field of type `BigNumber` which needs to be converted to a string) to ensure correct serialization. Through this parameter serialization function, the parameters of the business layer are converted into a format that the server can understand and process, ensuring the accuracy and validity of the network request parameters, so that the file upload request can successfully reach the server and be processed correctly.
[0118] When constructing the request function, taking a file upload scenario as an example, the obtained file upload cgiUrl and parameter serialization function are first integrated. The request function internally incorporates several important mechanisms to ensure the reliability and flexibility of network requests.
[0119] Retry Mechanism: A maximum number of retries (e.g., 3 times) and retry intervals are set (e.g., 1 second interval for the first retry, 2 seconds interval for the second, and 3 seconds interval for the third). When a file upload request is initiated, if it fails due to network failure (e.g., network connection interruption, server temporary unavailability), the request function will automatically re-initiate the request according to the set retry rules. If the request fails and the maximum number of retries has not been reached, a timer is set based on the retry interval, and the upload request is re-initiated after the timer expires. This retry mechanism improves the success rate of file uploads under unstable network conditions, avoiding frequent manual retries due to a single network failure, thus improving the user experience.
[0120] Cancel Request Mechanism: To allow users to cancel the file upload process as needed, the request function provides a cancellation function. This is typically achieved by setting a global variable or using AbortController (supported in modern browsers). When the user calls the cancel function (the returned function), the abort method of AbortController is triggered, terminating the ongoing file upload request, releasing system resources, and improving system responsiveness.
[0121] Automatic serialization mechanism: Inside the request function, a parameter serialization function is automatically called to serialize the parameters provided by the business layer, ensuring that the parameters are sent to the server in the correct format. For example, in the file upload request function mentioned above, the `serializeUploadParams` function is automatically called to serialize the file upload parameters before sending the request. This automatic serialization mechanism avoids the tedious operation of manually serializing parameters for each request, while also ensuring the consistency and accuracy of parameter serialization and reducing request failures caused by incorrect parameter formats.
[0122] Finally, these mechanisms are integrated to build a complete request function, so that when the business layer initiates a file upload request, it only needs to call this request function and pass in the corresponding cgiUrl and parameters to complete a reliable and flexible network request operation.
[0123] In file management applications, when building network layer request services, the obtained file upload cgiUrl, parameter serialization functions (such as serializeUploadParams), and request functions (such as uploadFileWithRetry or uploadFileWithCancel) are integrated.
[0124] For example, a `FileUploadService` class can be created to encapsulate these functionalities. The constructor of the `FileUploadService` class accepts `cgiUrl`, a parameter serialization function, and a request function as parameters, storing them as private attributes of the class. Then, an `uploadFile` method is provided. This method first calls the parameter serialization function to serialize the passed file upload parameters, and then calls the request function to initiate a file upload request. In this way, the various components of the network layer request service are organically combined, providing the business layer with a unified and convenient interface to initiate file upload requests. The business layer only needs to create an instance of the `FileUploadService` class and call its `uploadFile` method, passing in the file upload parameters, to complete the file upload operation. It does not need to worry about the underlying implementation details of the network request, such as `cgiUrl` configuration, parameter serialization, and request retry and cancellation mechanisms, thus improving development efficiency and system maintainability. The same approach can also be applied to other operations in file management applications (such as file download and deletion) and other types of applications (such as online document collaboration and data statistics). Based on the needs of different business operations, corresponding network layer request services can be built to achieve efficient and reliable network request processing.
[0125] The method provided in this application simplifies network request configuration, centrally manages cgiUrl for easy maintenance and environment switching; ensures correct parameter transmission, with the parameter serialization function converting business parameters into a server-processable format; enhances request reliability and flexibility, with retry mechanisms in the request function improving success rates, cancellation mechanisms optimizing resource utilization, and automatic serialization mechanisms ensuring parameter formats, thereby improving system stability and user experience; and optimizes the interaction between the business and network layers, with the constructed network layer request service providing a unified interface for the business layer, improving development efficiency and system maintainability.
[0126] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, the code responsible for managing related services in the network layer of the file management application is based on the JavaScript language;
[0127] Based on the target code for network layer request services, the code responsible for managing related business logic at the network layer in the file management application is constructed, including:
[0128] The code responsible for managing related business in the network layer of the file management application is converted into TypeScript-based code to obtain the target language code.
[0129] Based on the target language code, the network layer requests services, so that the network layer embeds the parameter values in the target language code to obtain the parameter assignment code;
[0130] Based on the lazy loading mechanism, the parameter assignment code is called to implement the code in the network layer of the file management application responsible for managing related business.
[0131] Understandably, in practical file management application development, if the original network layer code responsible for managing related business logic is written in JavaScript, it needs to be converted to adapt to the new technical architecture and gain the advantages of TypeScript. When converting to TypeScript code, the types of variables and function parameters must first be clearly defined. For the file upload function mentioned above, the `url` parameter should be a string, the `file` parameter might be of type `Blob` (representing binary file data), and the function return type should be `void` (because it doesn't return a specific value, but only performs the upload operation and processes the result). During the conversion process, other file management-related business logic code, such as file download, file deletion, and file list retrieval operations, also needs to be annotated with type and adjusted in a similar way. Through this conversion, leveraging TypeScript's static type checking capabilities, many potential type errors can be detected at compile time, improving code quality and maintainability. For example, if a string parameter is incorrectly used as a number in a file operation function, the TypeScript compiler will detect this error during compilation, rather than exposing the problem at runtime, thus reducing the difficulty and cost of debugging.
[0132] Taking file download as an example, after being converted to TypeScript, when a user clicks the download button, the business layer code needs to call the network layer request service to perform the download operation. In this way, the business layer code and the network layer request service work closely together. The business layer focuses on preparing business-related parameters, while the network layer handles the specific details of the request, nesting parameters into an appropriate request structure. This achieves separation of business logic and network request processing, improving code maintainability and scalability.
[0133] In file management applications, a lazy loading mechanism is used to optimize initialization performance when calling parameterized code. For example, the main interface of a file management application may contain multiple functional modules, such as a file upload module, a file download module, and a file sharing module. When the application starts, it does not immediately load the code for all these modules; instead, it only loads the code for the modules currently displayed or about to be used.
[0134] Taking the file download module as an example, assume that the code for the file download module is not loaded before the user clicks the download button. When the user clicks the download button, the code for the file download module is dynamically loaded using a lazy loading mechanism. In TypeScript, lazy loading can be implemented using dynamic imports (the `import()` function).
[0135] When a user clicks the download button, the `import()` function dynamically loads the `FileDownloadService` class, then creates instances of `FileDownloadService` and `FileManager`, and calls the `downloadSelectedFile` method of `FileManager` to perform the file download operation. This lazy loading mechanism reduces the amount of code loaded at application startup, improving application initialization speed. Especially in large file management applications with many functional modules and complex network layer code, lazy loading can significantly shorten application startup time and improve user experience. Simultaneously, this mechanism allows for more rational allocation of system resources, avoiding excessive memory consumption due to loading large amounts of unused code at application startup. When the user clicks the download button again or performs other file download-related operations, the code has already been loaded, allowing for rapid response and further improving application performance and responsiveness.
[0136] The method provided in this application enhances code quality and maintainability by converting JavaScript code into TypeScript code and using its static type checking to detect errors at compile time; optimizes the collaboration between the business and network layers by calling network layer requests for services and nesting parameter values to separate business logic from network request processing; and improves system performance by using a lazy loading mechanism to reduce the amount of code loaded at startup, speed up initialization, allocate resources reasonably, and improve application response speed and user experience, making it particularly suitable for complex file management applications.
[0137] For easier understanding, please refer to Figure 3 , Figure 3 The technical architecture of the network layer optimization method provided in this application embodiment is as follows. The entire architecture revolves around the cloud disk CGI service, and it is divided into three main parts: providing utils for external services, providing serializers for database use, and providing service APIs for external services.
[0138] 1. Provide utils services to the outside world:
[0139] 1) BigInt JSON Parsing / Serialization: This function handles JSON parsing and serialization of large integers (BigInt). In data processing, when dealing with large numbers that exceed the range of the JavaScript Number type, this specialized method ensures accurate data conversion. For example, it's used when dealing with data involving large values such as file size and storage capacity, ensuring the correct conversion of this data in JSON format.
[0140] 2) Inject Request Function: This module is responsible for injecting specific functions into the request process. It may be used to handle network requests, ensuring that the request carries the necessary functionality and parameters when sent. When a user initiates an operation request (such as file upload or download), it injects necessary validation and processing functions into the request to ensure that the request can be processed correctly.
[0141] 3) Get Large Number Data Type (getBigNumber): This module is used to obtain and process the data type of large numbers. It ensures that large numbers can be handled correctly in data operations, avoiding data type errors. It is used in scenarios involving large number calculations or processing, such as disk capacity statistics and file size calculations, to obtain and process this large numerical data.
[0142] 2. Provide a serializer for database use:
[0143] 1) Request Param Serializer: This module is responsible for serializing request parameters. It converts various parameters in the request into a format suitable for transmission over the network and storage in the database. When a user initiates an operation request (such as a file search, operation request, etc.), the parameters in the request (such as search keywords, operation type, etc.) are serialized for transmission over the network and storage in the database.
[0144] 2) Response Serializer: This module is responsible for serializing response data. It converts the response data returned by the database or server into a format suitable for transmission over the network and parsable by the client. When the server processes a user request and returns data (such as a file list, operation results, etc.), this data is serialized so that it can be transmitted over the network to the client and correctly parsed.
[0145] 3. Provide ServiceAPI services to the outside world:
[0146] 1) Disk Index Service: Responsible for managing index information on the disk. It ensures that files on the disk can be quickly found and accessed, improving file retrieval efficiency by maintaining index data. When a user performs a file search operation, the disk index service quickly locates files that meet the search criteria, improving search speed.
[0147] 2) Disk Login Service: This service handles user login operations to the disk system. It verifies the user's identity and permissions, ensuring that only authorized users can access and operate disk resources. When a user attempts to log in to the cloud disk system, the disk login service verifies the user's username, password, and other login information, and determines the range of disk resources the user can access based on their permissions.
[0148] 3) Disk File Batch Download Service: This service handles users' batch downloads of disk files. It coordinates the download process of multiple files, ensuring efficient and stable download operations. When a user selects multiple files in the cloud drive system and initiates a batch download request, the disk file batch download service manages the download process for these files, including allocating download bandwidth and handling download queues.
[0149] 4) Disk Management Service (disk_mgr_service): Responsible for the management and maintenance of disk resources. It includes functions such as disk space allocation, disk optimization, and disk fault detection to ensure the normal operation of the disk system. When disk space is insufficient or disk performance degrades, the disk management service takes corresponding measures, such as cleaning up temporary files and optimizing the disk storage structure, to ensure the normal use of the disk system.
[0150] 4. Type Declaration: This involves declaring and defining data types. It ensures the consistency and accuracy of data types throughout the architecture. Type declarations are used in various service and tool modules to define data structures and data types, avoiding errors caused by data type mismatches.
[0151] 1) Enumerations: Used to define a set of constant values. They are used throughout the architecture to represent fixed states or options. For example, in file permission settings, enumerations can be used to represent read-only, write-only, and execute permission states.
[0152] 2) Interfaces: Used to define the interaction specifications between modules. They ensure that communication between different modules follows a unified standard. Between various service and tool modules, interfaces define the format and specifications for data interaction, ensuring the modularity and scalability of the system.
[0153] For easier understanding, please refer to Figure 4 , Figure 4 This demonstrates the architectural changes of the WeDrive Node.js Business Manager module before and after its refactoring. Before the refactoring, JavaScript was used. Multiple business logic modules were responsible for handling specific business operations. Business logic processing involved nested parameter creation using new classes. These modules would call network layer interfaces to retrieve data or perform operations. After processing the business logic, the data was returned to the rendering layer for display. Before the refactoring, initializing all Manager modules using `require.js` was slow.
[0154] After refactoring, TypeScript (TS) was used, and type declarations were improved. This helped improve code readability and maintainability. Similar to before the refactoring, there are still multiple business logic modules. Unlike before, when calling the network layer interface, after the refactoring, network layer services are called directly. This likely means that calling the network layer is more direct and efficient. As before, data is returned to the rendering layer after processing the business logic. After the refactoring, a lazy import mechanism was adopted. This means that modules are only loaded on their first call, thus improving initialization speed and avoiding unnecessary module loading.
[0155] The overall architectural changes include:
[0156] 1. Language Change: The language changed from JavaScript (js) to TypeScript (ts), and type declarations were improved. This enabled more rigorous type checking at compile time, reducing runtime errors.
[0157] 2. Network layer invocation method: Shifting from calling network layer interfaces to calling network layer services may optimize the network layer invocation process and improve the efficiency of data acquisition and operation.
[0158] 3. Module loading mechanism: The lazy loading mechanism is adopted to avoid loading all modules during initialization, thereby improving the module loading speed and optimizing system performance.
[0159] After refactoring, the overall system performance was improved through lazy loading and optimized network layer calls, particularly in module loading and network data processing. Code quality was also improved; the use of TypeScript and more robust type declarations enhanced readability and maintainability, reducing errors caused by type mismatches.
[0160] In an optional embodiment of the network layer optimization method provided in the above embodiments of this application, the method is executed by a terminal, and the method further includes:
[0161] Obtain the application programming interface and initial request data corresponding to the network layer request service;
[0162] Based on the application programming interface (API) and the initial request data, the request function corresponding to the network layer request service is called to obtain the target request data. The target request data is obtained by formatting the initial request data using the request function.
[0163] The target request data is sent to the server through the general gateway interface. The server processes the target request data, obtains the initial return data, and sends the initial return data to the terminal.
[0164] Receive the initial return data sent by the server;
[0165] The initial returned data is parsed to obtain the target returned data.
[0166] Understandably, in file management applications, such as when a user clicks the "Search File List" button on the client interface, the client needs to obtain the API for querying the file list corresponding to the network layer request service, as well as initial request data. The initial request data may include the user's identity (for permission verification) and query conditions (such as filename keywords, file type filtering, etc.). Then, based on the obtained API and initial request data, the client calls the request function corresponding to the network layer request service. Once the target request data is obtained, it is sent to the server via the Common Gateway Interface (CGI). Upon receiving the target request data, the server processes it according to the request type and data content. For example, in a file query request, the server filters file information in the database based on the query conditions, constructs an initial return data object containing information such as the file list and file attributes, and then sends it back to the terminal. After receiving the initial return data from the server, the terminal needs to parse the format to suit the client's display and processing requirements. For example, if the file size in the file list data returned by the server is a number in bytes, but the client needs to display it in a more user-friendly format (such as KB, MB), unit conversion and other parsing operations are required.
[0167] For easier understanding, please refer to Figure 5 , Figure 5 The call process for a single network layer service API is shown.
[0168] As in step S1010, a service API is provided for business users to call, serving as the entry point for interaction between business code and the network layer. As in step S1020, through this interface, business code can initiate various network requests, such as retrieving file information and performing file operations, encapsulating complex network layer operations behind this unified interface, making business code calls more concise and convenient. As in step S1030, when business code calls the `service.request` function, a parameter serialization function is first triggered. This function formats the passed parameters according to predefined rules (usually based on definitions in the proto file), creating a standard-compliant request parameter body. For different types of data (such as basic data types, nested objects, or arrays), they are converted and organized according to corresponding rules to ensure that the request parameters accurately express the business intent and meet the requirements of the backend service. For example, object parameters in the business code are converted to a format suitable for network transmission (such as JSON strings), and data type mapping and encoding are handled correctly. As in step S1040, after the request parameters are formatted, a CGI request is sent to the backend service based on the formatted request parameters to obtain the required data or perform corresponding operations. This process involves establishing a network connection with the backend server, sending request data, and waiting for a response. It also requires handling various network communication scenarios, such as network latency and server errors. The network layer request service has the ability to automatically retry and cancel requests to improve reliability and flexibility. For example, if a temporary network failure causes a request to fail, the automatic retry mechanism can re-initiate the request under certain conditions, increasing the chance of success. Conversely, when a user cancels an operation or the request times out without a response, the cancel request function can terminate the request promptly, releasing system resources. As in step S1050, after receiving the response data from the backend service, a response standardization function is called to format the data. This function converts the data returned from the backend from a network transmission format into a data structure that the business code can directly use. For example, it parses JSON data into corresponding objects or arrays and performs necessary data validation and preprocessing to ensure data accuracy and integrity. Finally, as in step S1060, the processed response data is returned to the business code, allowing the business code to perform subsequent business logic processing based on the returned result, such as updating the interface display and storing data.
[0169] This design pattern makes the network layer's functions modular and standardized, improving code maintainability and scalability. At the same time, through standardized processing of parameters and responses, it ensures the accuracy and compatibility of data during network transmission, reduces the coupling between business code and the network layer, and makes the entire system more flexible and easier to develop and maintain.
[0170] The method provided in this application implements a complete business process. By acquiring API and initial data, calling request functions, interacting with the server, and parsing returned data, it ensures the accurate transmission and processing of data between the terminal and the server; improves user experience by converting server data into a format applicable to the client, making feedback information clear and accurate; enhances system collaboration by clarifying the operations of each step of the interaction between the terminal and the server, promoting the smooth operation of business functions, and ensuring the stable operation of applications such as file management.
[0171] Please see Figure 6 , Figure 6 Figure (A) shows a structural diagram of a network layer optimization device. The network layer optimization device 1110 includes:
[0172] Definition module 1101 is used to define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file; wherein, the parameter type is used to characterize the data type, and the parameter structure is used to characterize a data unit composed of at least two parameter types;
[0173] Create module 1102 to create a target serialization function based on the target protocol buffer file;
[0174] Module 1103 is used to build a network layer request service based on the target protocol buffer file and the target serialization function;
[0175] Optimization module 1104 is used to remove unused code from the code of network layer request service through code optimization mechanism to obtain the target code of network layer request service;
[0176] Module 1103 is also used to build the target code for network layer request services in the file management application, which is responsible for managing related business in the network layer.
[0177] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, the parameter structure includes a message structure, and the parameter type includes an enumeration type.
[0178] Module 1101 is also defined for:
[0179] Define the message structure in the protocol buffer file as an interface in the TypeScript language. The interface is used to define the structure of an object, the signature of a function, or the contract that a class needs to follow.
[0180] Define the enumeration types in the protocol buffer file as a combination of interfaces and constant variables in the TypeScript language, where constant variables are used to represent variables with fixed values.
[0181] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, the creation module 1102 is further configured to:
[0182] Based on the parameter structure in the protocol buffer file, an initial request parameter is created. The initial request parameter contains M fields, and each field corresponds to a default value. M is an integer greater than or equal to 1.
[0183] Get the parameter values corresponding to M fields, and assign values to the initial request parameters according to the parameter values corresponding to M fields to obtain the assigned request parameters;
[0184] Convert the field types of K target fields out of M fields in the assignment request parameters to obtain the target request parameters, where K is an integer greater than or equal to 1 and less than or equal to M;
[0185] The parameter types of the target request parameters are formatted to obtain the target serialization function.
[0186] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, the target field is an unsigned 64-bit integer field, and the parameter type of the initial serialization function is a nested type;
[0187] Module 1102 was created and is also used for:
[0188] Convert the type of the K target fields in the assignment request parameters to a large number type to obtain the target request parameters.
[0189] The parameter types of the target request parameters are converted to obtain the target serialization function, including:
[0190] Call the nested formatting function to format the parameter types of the target request parameters, and obtain the target serialization function.
[0191] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, the construction module 1103 is further configured to:
[0192] Obtain the general gateway interface;
[0193] Based on the parameter structure and parameter types in the protocol buffer file, and the target serialization function, construct the parameter serialization function;
[0194] Based on the general gateway interface and parameter serialization function, a request function is constructed, which includes a retry mechanism, a request cancellation mechanism, and an automatic serialization mechanism.
[0195] Based on the general gateway interface, parameter serialization function, and request function, construct the network layer request service.
[0196] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, the code responsible for managing related services in the network layer of the file management application is based on the JavaScript language;
[0197] Module 1103 is also used for:
[0198] The code responsible for managing related business in the network layer of the file management application is converted into TypeScript-based code to obtain the target language code.
[0199] Based on the target language code, the network layer requests services, so that the network layer embeds the parameter values in the target language code to obtain the parameter assignment code;
[0200] Based on the lazy loading mechanism, the parameter assignment code is called to implement the code in the network layer of the file management application responsible for managing related business.
[0201] In an optional embodiment of the network layer optimization apparatus provided in the above embodiments of this application, such as Figure 6 The optimization device 1110 for the (B) network layer also includes:
[0202] The acquisition module 1105 is used to acquire the application programming interface and initial request data corresponding to the network layer request service;
[0203] Module 1106 is invoked to call the request function corresponding to the network layer request service based on the application programming interface and the initial request data, in order to obtain the target request data. The target request data is obtained by formatting the initial request data using the request function.
[0204] The sending module 1107 is used to send target request data to the server through a general gateway interface. The server processes the target request data, obtains initial return data, and sends the initial return data to the terminal.
[0205] The receiving module 1108 is used to receive the initial return data sent by the server;
[0206] Parsing module 1109 is used to parse the format of the initial returned data to obtain the target returned data.
[0207] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0208] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0209] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.
[0210] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0211] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0212] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a server or terminal device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0213] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method of optimizing a network layer, characterized by, include: Define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file; wherein, the parameter types are used to characterize the data type, and the parameter structure is used to characterize a data unit composed of at least two parameter types; Based on the target protocol buffer file, create a target serialization function; Based on the target protocol buffer file and the target serialization function, a network layer request service is constructed. By using a code optimization mechanism, unused code in the code for requesting services at the network layer is removed to obtain the target code for requesting services at the network layer. Based on the target code for the network layer request service, the code responsible for managing related business in the network layer of the file management application is constructed.
2. The method as described in claim 1, characterized in that, The parameter structure includes a message structure, and the parameter type includes an enumeration type. The parameter structure and parameter types in the defined protocol buffer file include: Define the message structure in the protocol buffer file as an interface in the TypeScript language, whereby the interface is used to define the structure of an object, the signature of a function, or the contract that a class needs to follow. The enumeration type in the protocol buffer file is defined as a combination of an interface and a constant variable in the TypeScript language, wherein the constant variable is used to represent a variable with a fixed value.
3. The method as described in any one of claims 1-2, characterized in that, The step of creating a target serialization function based on the target protocol buffer file includes: Based on the parameter structure in the protocol buffer file, an initial request parameter is created, wherein the initial request parameter contains M fields, and each field corresponds to a default value, where M is an integer greater than or equal to 1; Obtain the parameter values corresponding to the M fields, and assign values to the initial request parameters according to the parameter values corresponding to the M fields to obtain the assigned request parameters; The field types of K target fields out of the M fields in the assignment request parameters are converted to obtain the target request parameters, where K is an integer greater than or equal to 1 and less than or equal to M; The parameter type of the target request parameter is formatted to obtain the target serialization function.
4. The method as described in claim 3, characterized in that, The target field is an unsigned 64-bit integer, and the parameter type of the initial serialization function is a nested type. The process of converting the field types of K target fields out of M fields in the assignment request parameters to obtain the target request parameters includes: Convert the type of the K target fields in the assignment request parameters to a large number type to obtain the target request parameters; The step of converting the parameter type of the target request parameter to obtain the target serialization function includes: The nested formatting function is invoked to format the parameter type of the target request parameter, thereby obtaining the target serialization function.
5. The method according to any one of claims 1-4, characterized in that, The construction of the network layer request service based on the target protocol buffer file and the target serialization function includes: Obtain the general gateway interface; Based on the parameter structure and parameter types in the protocol buffer file, and the target serialization function, a parameter serialization function is constructed; Based on the general gateway interface and the parameter serialization function, a request function is constructed, wherein the request function is equipped with a retry mechanism, a request cancellation mechanism and an automatic serialization mechanism; The network layer request service is constructed based on the general gateway interface, the parameter serialization function, and the request function.
6. The method according to any one of claims 1-2, characterized in that, The network layer code responsible for managing related business in the file management application is based on the JavaScript language; The target code based on the network layer request service is used to construct the code in the file management application responsible for managing related business at the network layer, including: The code responsible for managing related business in the network layer of the file management application is converted into TypeScript-based code to obtain the target language code. Based on the target language code, the network layer request service is invoked so that the network layer embeds the parameter values in the target language code to obtain the parameter assignment code; Based on the lazy loading mechanism, the parameter assignment code is called to implement the code responsible for managing related business in the network layer of the file management application.
7. The method according to any one of claims 1-6, characterized in that, The method is executed by a terminal, and the method further includes: Obtain the application programming interface and initial request data corresponding to the network layer request service; Based on the application programming interface and the initial request data, the request function corresponding to the network layer request service is called to obtain the target request data, wherein the target request data is obtained by the request function after formatting the initial request data; The target request data is sent to the server through a general gateway interface. The server processes the target request data to obtain initial return data, and then sends the initial return data to the terminal. Receive the initial return data sent by the server; The initial returned data is parsed to obtain the target returned data.
8. A network layer optimization device, characterized in that, include: A definition module is used to define the parameter structure and parameter types in the protocol buffer file to obtain the target protocol buffer file; wherein, the parameter type is used to characterize the data type, and the parameter structure is used to characterize a data unit composed of at least two parameter types; A module is created to create a target serialization function based on the target protocol buffer file; The construction module is used to construct a network layer request service based on the target protocol buffer file and the target serialization function; The optimization module is used to remove unused code from the code of the network layer request service through a code optimization mechanism to obtain the target code of the network layer request service. The building module is also used to build the code responsible for managing related business in the network layer of the file management application based on the target code of the network layer request service.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the optimization method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the optimization method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the optimization method according to any one of claims 1 to 7.