Data acquisition method, system, electronic device and computer readable storage medium
Through the comparison mechanism of the hot update program and the state management unit, data requests are only sent when the input parameters change, which solves the problem of repeated data requests on the server-side performance load in React architecture program projects, and achieves improved response speed and code simplification. .
Patent Information
- Application Number
- CN202111084879.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-16
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-09-16
AI Technical Summary
In the existing technology, repetitive data requests in program projects based on the React architecture cause excessive performance load on the server side, affecting response speed, and developers need to write a large number of repetitive Hook functions, resulting in increased code complexity and maintenance difficulty.
The state management unit is called through the hot update program. Based on the comparison between the input parameters and the value of the state management unit, data request messages are only sent to the server when the parameters change to avoid repetitive requests and are programmed through independent hot update programs and applications. The interface controls data request actions and reduces code redundancy.
It effectively reduces server-side performance load, improves data request response speed, reduces resource occupation, simplifies code, and improves the readability and maintainability of program projects.
Smart Images

Figure CN113721964B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a data acquisition method, a data acquisition system, an electronic device, and a computer-readable storage medium based on computer technology. Background Art
[0002] With the development of computer technology, the number of codes for data requests between clients and servers in program projects is increasing. Taking a program project based on the React architecture and using Hook technology as an example, a program project often includes a large number of Hook functions for data requests. When developers call the Hook function to request data, they often habitually click the "Submit Request" button multiple times, that is, submit multiple data requests at a time. The server side needs to respond to each repetitive data request in multiple program projects one by one, which will cause a heavy performance load on the server side.
[0003] In addition, for a single program project, when the repetitive data request of the previous Hook function is waiting for a response, it will occupy the data request response time of the Hook function that is later in the sequence, causing request congestion and seriously affecting the response speed of each Hook function.
[0004] Therefore, an improved data acquisition method and system are needed to at least improve the above problems to some extent.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] The purpose of the embodiments of the present disclosure is to provide a data acquisition method, a data acquisition system, an electronic device and a computer-readable storage medium, so as to at least to a certain extent solve the heavy performance load on the server caused by repetitive data requests, and improve the response speed of each data request for a program project, thereby reducing resource usage and improving work efficiency.
[0007] According to one aspect of the present disclosure, a data acquisition method is provided, characterized by comprising:
[0008] Determine an input parameter input by a user, and set the value of the input parameter to the value of a first parameter of an application programming interface of the hot update program;
[0009] In response to a data request instruction initiated by a user, calling the application programming interface to call the hot update program;
[0010] Calling a preset first state management unit through the hot update program, and setting the first parameter to be associated with the first state management unit;
[0011] comparing the value of the first parameter with the value of the first state management unit;
[0012] When the value of the first parameter is different from the value of the first state management unit, updating the value of the first state management unit according to the value of the first parameter, and sending a data request message to the server based on the input parameter;
[0013] When the value of the first parameter is the same as the value of the first state management unit, the data request message is not sent to the server.
[0014] In an exemplary embodiment of the present disclosure, the method also includes: setting the second parameter of the application programming interface to be associated with a preset second state management unit through the hot update program; in response to the user setting the flag bit of the second parameter to enable and initiating a data request instruction, calling the application programming interface to call the hot update program; calling the second state management unit through the hot update program and changing the state of the second state management unit; and in response to the change in the state of the second state management unit, sending a data request message to the server based on the input parameter.
[0015] In an exemplary embodiment of the present disclosure, the method further includes: when the flag bit of the second parameter is set to enabled, in response to a timed acquisition instruction initiated by a user, sending a data request message to the server at a preset time interval.
[0016] In an exemplary embodiment of the present disclosure, the input parameters include input parameters of a function type, and determining the input parameters input by the user includes: receiving the input parameters of the function type input by the user and executing a corresponding function, and determining the input parameters based on a result of executing the corresponding function.
[0017] In an exemplary embodiment of the present disclosure, the input parameters further include default parameters, and determining the input parameters according to the result of executing the corresponding function includes: combining the result of executing the corresponding function with the default parameters to determine the input parameters.
[0018] In an exemplary embodiment of the present disclosure, after sending the data request message to the server side, the method further includes: obtaining the status of the data request from the server side; when the status of the data request is successful, feeding back the success status and the data received from the server side to the user; when the status of the data request is failed, feeding back the failure status to the user.
[0019] In an exemplary embodiment of the present disclosure, the method also includes: calling a preset third state management unit through the hot update program and setting the data received from the server side as the value of the third state management unit, and setting one or more program components to be associated with the third state management unit through the hot update program; when the value of the third state management unit changes, updating the values of corresponding parameters in the one or more program components according to the changed value of the third state management unit.
[0020] According to one aspect of the present disclosure, there is provided a data acquisition system, comprising:
[0021] A parameter input and processing module, used to determine the input parameters input by the user;
[0022] a hot update module, configured to set the value of the input parameter to the value of a first parameter of an application programming interface of the hot update module; and to be called accordingly and call a preset first state management unit when the application programming interface is called in response to a data request instruction initiated by a user, and to set the first parameter to be associated with the first state management unit;
[0023] A data request and status processing module is used to compare the value of the first parameter with the value of the first status management unit; when the value of the first parameter is different from the value of the first status management unit, the value of the first status management unit is updated according to the value of the first parameter, and a data request message is sent to the server based on the input parameter; when the value of the first parameter is the same as the value of the first status management unit, the data request message is not sent to the server.
[0024] According to one aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the above-mentioned methods by executing the executable instructions.
[0025] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, any one of the above methods is implemented.
[0026] The exemplary embodiments of the present disclosure may have some or all of the following beneficial effects:
[0027] Through the data acquisition method provided by the exemplary embodiment of the present disclosure, on the one hand, the hot update program calls the first state management unit, and sets the first parameter of its application programming interface to be associated with the first state management unit, and controls whether to send a data request message to the server side according to whether the value of the first parameter is the same as the value of the first state management unit, so that the data request action is triggered only when the user changes the input parameters and calls the application programming interface; and when the user does not change the input parameters but habitually submits data requests multiple times, the data request action will not be triggered; thereby, it can effectively avoid the server side having to respond to each repetitive data request one by one, thereby causing the risk of heavy performance load on the server side and slow data request response speed in the program project, thereby reducing resource usage and improving work efficiency. On the other hand, by controlling the action of sending data request messages to the server side by a hot update program and its application programming interface that are independent of the program project, in each program project, developers do not need to write a corresponding Hook function for each data request. Instead, they can call the hot update program through the application programming interface when needed to complete the data request action, thereby avoiding a large amount of repetitive or complex code in the program project, achieving lightweight program projects, and improving the readability and maintainability of program projects.
[0028] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0030] Figure 1 A flowchart of a data acquisition method according to an embodiment of the present disclosure is schematically shown;
[0031] Figure 2 Schematically shows a flow chart of performing data request through a hot update program and a data request and status processing program according to an embodiment of the present disclosure;
[0032] Figure 3 Schematically shows a flow chart of controlling a data request action by a second state management unit according to an embodiment of the present disclosure;
[0033] Figure 4 Schematically shows a flow chart for determining input parameters according to an embodiment of the present disclosure;
[0034] Figure 5 Schematically shows a flow chart of executing a data request according to an embodiment of the present disclosure;
[0035] Figure 6 A block diagram of a data acquisition system according to an embodiment of the present disclosure is schematically shown;
[0036] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0037] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0038] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0039] In the data acquisition method according to the present disclosure, based on the operation process of "input parameters-compare parameter values-send data request messages", different program modules can be set according to different functions, such as parameter input and processing program modules, hot update program modules, and data request and status processing program modules. The above-mentioned program modules can be integrated together according to actual needs to be implemented as a single program or NPM package, and the single program or NPM package can be downloaded from a server or server cluster independently of each other by each program project and called through a specific interface. In addition, in a possible implementation, the data acquisition method according to the present disclosure can be applied to acquire data in an asynchronous manner. In the subsequent description of the present disclosure, the data acquisition method according to the present disclosure will be exemplarily described based on the scenario of asynchronous data acquisition. In addition, the data acquisition method according to the present disclosure can be applied to terminal devices that can write and run program projects, such as but not limited to personal computers, handheld computer devices, etc., and the embodiments of the present disclosure are not particularly limited to this.
[0040] The technical solution of the embodiment of the present disclosure is described in detail below:
[0041] This example embodiment provides a data acquisition method. Figure 1 As shown, the data acquisition method may include the following steps:
[0042] Step S110. Determine an input parameter input by a user, and set the value of the input parameter as the value of the first parameter of the application programming interface of the hot update program;
[0043] Step S120. In response to a data request instruction initiated by a user, calling the application programming interface to call the hot update program;
[0044] Step S130. Calling a preset first state management unit through the hot update program, and setting the first parameter to be associated with the first state management unit;
[0045] Step S140. Compare the value of the first parameter with the value of the first state management unit;
[0046] Step S150. When the value of the first parameter is different from the value of the first state management unit, the value of the first state management unit is updated according to the value of the first parameter, and a data request message is sent to the server based on the input parameter;
[0047] Step S160: When the value of the first parameter is the same as the value of the first state management unit, the data request message is not sent to the server.
[0048] The above steps are described in more detail below by way of exemplary embodiments.
[0049] In step S110, an input parameter input by a user is determined, and a value of the input parameter is set as a value of a first parameter of an application programming interface of the thermal update program.
[0050] In this example embodiment, the processing program can be connected to the processing program through parameter input and can be connected to the processing program through ... Figure 2 The process shown in the figure can determine the input parameters input by the user; wherein the parameter input and processing program can provide a parameter input interface and an input interface for the user to operate to input parameters, and in step S210, the user can input parameters through the parameter input and processing program. For example, as shown in the following table, the input parameters that the user can enter may include:
[0051] Parameter name significance type query Data request service to be sent Promises params Query the parameters required by the data request service Object or function defaultParams Query the default parameters of the data request service Object
[0052] Table 1
[0053] Among them, the input parameter with a parameter name such as "query" can be used for the user to initiate a data request service, and the input parameter can be, for example, a parameter of the "Promise" type; wherein "Promise" is a callback function for transmitting a message of an asynchronous operation, that is, a function that promises to perform an asynchronous operation in the future. The input parameter with a parameter name such as "params" can include, for example, a request source, a request object, etc., which can be sent to the server and enable the server to query and send the requested data according to the input parameter; wherein the type of the input parameter can be an object or a function. The input parameter with a parameter name such as "defaultParams" can be a parameter of the object type, which can be the system default parameter of the input parameter with the parameter name "params" mentioned above. For example, if the user does not enter a parameter, the default parameter can be sent to the server and the server can query and send the requested data according to the default parameter. In view of this, in step S220, the parameter input and processing program can perform format verification on the input parameters, for example, verifying whether the format type of the input parameter named "params" is an object or a function, or verifying whether the format type of the input parameter named "defaultParams" is an object. When it is verified that the format of the input parameter does not conform to the type specified above, the program jumps to step S230, and an error prompt is popped up to the user on the graphical user interface of the program project, prompting that the format of the input parameter is incorrect, and then jumps to step S240 to end this parameter input and verification process.
[0054] Based on Figure 2In an example of the process shown, when the verification is completed and it is determined that the format of the input parameter meets the specified type, it jumps to step S250, and the parameter input and processing program determines whether the input parameter includes an input parameter of a function type. The input parameter of the function type can be associated with certain external data, and the associated external data needs to be called to execute the corresponding function, so as to determine the final input parameter according to the result of executing the corresponding function. For example, the input parameter can include an input parameter of a sorting function type to select the user name of the user ranked in the top 3 in the sorting result as the final input parameter. After receiving the input parameter of the sorting function type input by the user, the user list can be called and the corresponding sorting function can be executed, and the user name ranked in the top 3 can be determined as the final input parameter; wherein the input parameter of the function type can be written in the form of function(){return something}, for example. Therefore, when it is determined that the input parameter is an input parameter of a function type, it can jump to step S260, and the parameter input and processing program receives the input parameter of the function type and executes the corresponding function to obtain the result of the execution. When the input parameter does not include the default parameter, the result of executing the corresponding function is the final input parameter.
[0055] Through the above examples, users are not limited to inputting parameters in the form of objects, but can flexibly automatically determine the parameters to be input by executing functions before triggering request data, thereby reducing the user's workload when writing programs, reducing manpower waste and improving programming efficiency.
[0056] Based on Figure 2 In another example of the process shown, the input parameters may include both the input parameters of the function type input by the user and the default parameters. In this case, after executing the corresponding function in the manner of the above example, the process may jump to step S270 to merge the result obtained by executing the corresponding function with the default parameters, thereby determining and outputting the merged final input parameters in step S280. For example, when the parameters input by the user include parameters of the sorting function type, the user name ranked first obtained by executing the sorting function is Lily, that is, param = {user:lily}, and the input parameters also include the default parameter "age is 25 years old", that is, defaultParams = {age:25}; the result of executing the function may be merged with the default parameter to obtain the final input parameter {user:lily,age:25}, so that the server can query and send the requested data according to the final input parameter.
[0057] Through the above example, users can set the parameters with higher commonality as default parameters, and automatically merge the default parameters with the input parameters when requesting data, and send the merged parameters to the server as the final input parameters. In this way, when setting input parameters, users do not need to repeatedly enter the parameters with higher commonality, thus saving the time cost of input operations and helping to improve the user's writing efficiency.
[0058] After determining the input parameter, the value of the input parameter can be set to the value of the first parameter of the application programming interface (API) of the hot update program through the hot update program. In this example embodiment, the hot update program may include, for example, an application programming interface named "setParams", and by calling this application programming interface, the call to the hot update program can be implemented. The application programming interface can be implemented in the form of a function, for example, and can include multiple parameters. The hot update program can, for example, obtain the input parameter input by the user through a specific interface call or the like, and can set the value of the input parameter to the value of the first parameter among the multiple parameters of the application programming interface. For example, according to the aforementioned example, the value of the first parameter can be set to {user:lily,age:25}.
[0059] In step S120, the application programming interface is called in response to a data request instruction initiated by a user to call the hot update program.
[0060] In this example implementation, the user may, for example, click a "submit request" button on the graphical user interface of the program project to execute the data request logic line, thereby invoking the application programming interface and further invoking the corresponding hot update program.
[0061] In step S130, a preset first state management unit is called through the thermal update program, and the first parameter is set to be associated with the first state management unit.
[0062] In this example implementation, when the hot update program is called, it can call the preset first state management unit. In one example, the first state management unit can correspond to the concept of "atom" in the state management library named Recoil, for example. Among them, the "atom" can be a state management unit that can be shared by multiple program components. When the state of the atom changes or is updated, all program components that subscribe to the atom can use the corresponding new value to re-render or share the state of the atom, so that all subscribed program components can automatically update or re-execute the operation action, so that full rendering can be avoided when the parameters are updated. In the subsequent description of this disclosure, the technical solution of the embodiment of the present disclosure will be described by taking the state management unit corresponding to the "atom" in the Recoil state management library as an example. In addition to the Recoil state management library, for example, other state management libraries such as Redux can also be used to implement similar functions, and this example implementation is not particularly limited to this. The first state management unit can be pre-written by the user, that is, the writer of the program project or other writers, and it is independent of the program project and can be called by the hot update program. For example, writing and setting the first state management unit may be implemented by the following logic lines:
[0063] ParamState = atom({
[0064] Key:'',
[0065] Default:{}
[0066] }).
[0067] Among them, "Key" is the globally unique identifier of the first state management unit, and "Default" is the default value of the first state management unit.
[0068] After calling the first state management unit, the hot update program may set the first parameter to be associated with the first state management unit, that is, the application programming interface may be used as a program component and the first parameter of the application programming interface may be subscribed to the first state management unit.
[0069] In addition, in addition to the hot update program, as mentioned above, a data request and status handler can be set up to execute a data request action in response to a state change of the first state management unit. The preset first state management unit can be set in the data request and status handler, so that when the state or value of the first state management unit changes, the data request and status handler can correspondingly execute the action of requesting data from the server.
[0070] In steps S140, S150 and S160, the value of the first parameter is compared with the value of the first state management unit; when the value of the first parameter is different from the value of the first state management unit, the value of the first state management unit is updated according to the value of the first parameter, and a data request message is sent to the server based on the input parameter; when the value of the first parameter is the same as the value of the first state management unit, the data request message is not sent to the server.
[0071] In this example implementation, the value of the first parameter can be compared with the value of the first state management unit by the data request and state handler. Wherein, when the user writes a program project, the default input parameter can be pre-written in the logic line of the program project, and when the program project is started for the first time and the data request is executed for the first time, a data request message can be directly sent to the server side based on the default input parameter, and at this time, there is no need to call the application programming interface and the value of the default input parameter can be set to the value of the first parameter. At the same time, when the data request and state handler associated with it are determined before the program project is started for the first time, the value of the default input parameter can also be set to the value of the first state management unit. Therefore, after the data request is executed for the first time, the value of the first parameter is the same as the value of the first state management unit.
[0072] In subsequent operations, if the user changes the input parameter and, for example, clicks the "Submit Request" button on the graphical user interface of the program project, the value of the changed input parameter can be set to the value of the first parameter, and the corresponding logic line can be executed to call the application programming interface, thereby calling the first state management unit by calling the hot update program; at this time, when the data request and state handler compares the value of the first parameter with the value of the first state management unit, the value of the first parameter is the value of the changed input parameter, while the value of the first state management unit is still the value of the default input parameter, so the two are different; in this case, the data request and state handler will update the value of the first state management unit according to the value of the first parameter, that is, the value of the changed input parameter; and the update of the value of the first state management unit means that the state of the first state management unit has changed, therefore, in response to the change in the state of the first state management unit, the data request and state handler can send a data request message to the server based on the changed input parameter.
[0073] However, if the user does not change the input parameters, but only habitually clicks the "Submit Request" button on the graphical user interface of the program project multiple times, then the value of the first parameter and the value of the first state management unit are still the same when the data request and state handler compare. In this case, the value of the first state management unit is not updated, that is, the state of the first state management unit has not changed, and the data request and state handler will not send a data request message to the server, thereby caching and deleting repetitive invalid data requests when the user has not changed the input parameters.
[0074] In summary, the data acquisition method according to this exemplary embodiment may mainly include the following steps: Figure 3 The steps shown are: at S310, when the input parameter input by the user changes, the first parameter can change accordingly; at S320, when the user executes the corresponding logic line to submit a data request, the application programming interface can be called; at S330, since the application programming interface is called, the hot update program is called accordingly, and then the first state management unit is called through the hot update program; at S340, when the value of the first parameter is different from the value of the first state management unit and the value of the first state management unit is updated according to the value of the first parameter, the state of the first state management unit is changed, so that the data request and state handler send a data request to the server; at S350, after receiving the requested data from the server, the requested data can be output to the user.
[0075] Through the data acquisition method provided by the exemplary embodiment of the present disclosure, on the one hand, the hot update program calls the first state management unit, and sets the first parameter of its application programming interface to be associated with the first state management unit, and controls whether to send a data request message to the server side according to whether the value of the first parameter is the same as the value of the first state management unit, so that the data request action is triggered only when the user changes the input parameters and calls the application programming interface; and when the user does not change the input parameters but habitually submits data requests multiple times, the data request action will not be triggered; thereby, it can effectively avoid the server side having to respond to each repetitive data request one by one, thereby causing the risk of heavy performance load on the server side and slow data request response speed in the program project, thereby reducing resource usage and improving work efficiency. On the other hand, by controlling the action of sending data request messages to the server side by a hot update program and its application programming interface that are independent of the program project, in each program project, developers do not need to write a corresponding Hook function for each data request. Instead, they can call the hot update program through the application programming interface when needed to complete the data request action, thereby avoiding a large amount of repetitive or complex code in the program project, achieving lightweight program projects, and improving the readability and maintainability of program projects.
[0076] In one example, in addition to the first state management unit, a second state management unit may be used to control the data request and the state processing program to send the data request. Figure 3 The exemplary data acquisition method shown may include the following steps:
[0077] In step S410, the second parameter of the application programming interface is set to be associated with the preset second state management unit by the hot update program. In practical applications, except that the user requests data from the server side according to the demand of the current program project, the data on the server side may also be regularly updated over time, and the user needs to send a data request every corresponding time so as to pull the updated data from the server side, but the user does not change the input parameter input at this time. In this case, in addition to the first state management unit, the writing staff can also pre-write the second state management unit, and set it in the data request and state handling program, so that the second state management unit can be independent of the program project and can be called by the hot update program, and similarly to the first state management unit, the state change of the second state management unit can trigger the data request and state handling program to send a data request message to the server side. And the hot update program can set the second parameter of its application programming interface to be associated with the second state management unit.
[0078] In step S420, in response to the user setting the flag of the second parameter to enable and initiating a data request instruction, the application programming interface is called to call the hot update program. After the second parameter is associated with the second state management unit, the flag of the second parameter can be used to control whether the second state management unit is enabled. For example, the user can set the state of the flag of the second parameter to "true", that is, set it to the enabled state, then the second state management unit can be enabled accordingly to control the sending of the data request; and the user can also set the state of the flag of the second parameter to "false", that is, set it to the disabled state, then the second state management unit is not enabled to control the sending of the data request. It can be set that when the state of the flag of the second parameter is "false", the state of the second state management unit is forcibly locked in the current state, so that even if the second state management unit is called, its state does not change, and the data request and state handler will not be triggered to send a data request message to the server. For example, a check box named "update flag" may be provided on the graphical user interface of the program project, and two options of "true" and "false" may be provided, and the user may set the state of the flag of the second parameter to "true" or "false" by checking one of the options. When the user sets the state of the flag of the second parameter to "true" and executes the corresponding logic line to initiate the data request instruction, similar to the above exemplary description, the application programming interface may be called to call the hot update program accordingly.
[0079] In step S430, the second state management unit is called by the thermal update program, and the state of the second state management unit is changed. After the thermal update program is called, it can detect whether the state of the flag bit of the second parameter is "true" or "false". When it is detected that the state of the flag bit of the second parameter is "false", it is determined not to enable the second state management unit and not to perform subsequent operations; and when it is detected that the state of the flag bit of the second parameter is "true", the thermal update program can call the second state management unit and change the state of the second state management unit. For example, the state of the second state management unit can be changed by changing the value of the second state management unit; for example, the default value of the second state management unit can be 0. When the value of the second state management unit is updated from the default value 0 to 1, the state of the second state management unit can be changed accordingly.
[0080] In step S440, in response to the change of the state of the second state management unit, a data request message is sent to the server based on the input parameter. Similar to the above exemplary description, the change of the state of the second state management unit will also trigger the data request and state processing program to send a data request message to the server. Therefore, when a change in the state of the second state management unit is detected, the data request and state processing program can send a data request message based on the input parameter.
[0081] Through the above examples, in the application scenario where the data on the server side is updated regularly over time and the user needs to pull the updated data from the server side at a fixed time, a self-controlled switch means can be provided for the user, so that the user can self-control the opening and closing of the cache repeated data request function through the above second state management unit as needed when the input parameters have not changed. Thereby, the user can flexibly select the corresponding data acquisition strategy according to different application scenarios, which improves the versatility of the data acquisition method according to the present disclosure and helps to improve the work efficiency of the user in acquiring data.
[0082] In another example, when the flag of the second parameter is set to "true", that is, the enabled state, the user can also execute the corresponding logic line to initiate a timed acquisition instruction. In the timed acquisition instruction, for example, the user can set the timing duration, for example, set it to send a data request message to the server every 1 minute. Based on the user's settings, the state of the second state management unit can be changed at a set time interval, for example, every 1 minute, so that the data request and state handler are triggered to send a data request message to the server. Through this example, the operational burden of users pulling data in application scenarios that require regular data updates is further reduced, thereby helping to reduce manpower consumption and improve the operational efficiency of programmers.
[0083] In one example, it is also possible to Figure 5The process shown determines the status of the data request sent. In step S510, the user can set the input parameters; usually, when the program project is started, the data request message will be automatically sent to the server based on the default input parameters, but sometimes the user does not want the program project to automatically obtain data as soon as it is started. In this case, the user can, for example, add a "wait" identifier to the default input parameter. In step S520, the data request and status handler can check whether the input parameter carries the wait identifier. If it does, it jumps to step S570, does not send the data request message and ends this process until the user executes the logic line to call the application programming interface of the hot update program; if it does not, it jumps to step S530, and accordingly executes the data request, for example, through the Fetch function, and at the same time, it can also obtain the status of the data request from the server, for example, through the React Loadable service provided by the data request and status handler, wherein the status of the data request can include several states such as requesting, request success, and request error. And in step S540, the data request and status processing program can determine whether the data request is successful. If the request fails, it jumps to step S550, feeds back the failure status to the user and then jumps to step S570 to end the process; if the request is successful, it jumps to step S560, the data request and status processing program can feed back the success status and the corresponding data received from the server to the user, and finally reaches step S570 and ends the process.
[0084] Through the above example, the user can control the timing of initiating a data request through the wait identifier, thereby enhancing the usability and controllability of the program project; at the same time, the data request and status handler itself can provide a service for obtaining the status of the data request, so that the user can intuitively and quickly understand the status of the current request after sending a data request through the data request and status handler, without having to write additional code in the program project to ensure the status acquisition function, making the program project further lightweight, thereby helping to save labor costs and improving the readability and maintainability of the program project.
[0085] In one example, in addition to the first and second state management units, the writer can also pre-write a third state management unit and set it in the data request and state handler, so that the third state management unit can also be independent of the program project and can be called by the hot update program. The value of the third state management unit can be set to the data received from the server through the hot update program, and one or more program components in the program project can be set to be associated with the third state management unit, that is, subscribe to the third state management unit. As described above, according to the data acquisition method disclosed in the present invention, when the state of the state management unit changes or is updated, all program components subscribing to the state management unit can adopt the corresponding new value to automatically re-render or share the state of the atom. Therefore, when the data obtained from the server changes, that is, when the value of the third state management unit changes, the value of the corresponding parameter in one or more program components subscribing to the third state management unit will also be updated accordingly, without the need to fully re-render or recalculate the one or more program components.
[0086] Through the above-mentioned example, by utilizing the association between the third state management unit and the corresponding one or more parameters, fine-grained and decentralized data management and a data update method that can be used as needed are realized. As a result, when the updated data is obtained from the server, it is not necessary to update and render the overall architecture of the program components involved, thereby reducing the computing load of the program project in updating data, thereby helping to reduce resource usage and correspondingly improve the work efficiency of the program project.
[0087] It should be noted that although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0088] Furthermore, in this exemplary embodiment, a data acquisition system is also provided. Figure 6 As shown, the data acquisition system 600 may include a parameter input and processing module 610, a data request and status processing module 620, and a hot update module 630. Among them:
[0089] The parameter input and processing module 610 may be used to determine input parameters input by a user;
[0090] The hot update module 630 may be used to set the value of the input parameter to the value of the first parameter of the application programming interface of the hot update module; and when the application programming interface is called in response to a data request instruction initiated by a user, it is called accordingly and calls a preset first state management unit, and sets the first parameter to be associated with the first state management unit;
[0091] The data request and status processing module 620 can be used to compare the value of the first parameter with the value of the first status management unit; when the value of the first parameter is different from the value of the first status management unit, the value of the first status management unit is updated according to the value of the first parameter, and a data request message is sent to the server based on the input parameter; when the value of the first parameter is the same as the value of the first status management unit, the data request message is not sent to the server.
[0092] In an exemplary embodiment of the present disclosure, the hot update module 630 can also be used to set the second parameter of the application programming interface to be associated with a preset second state management unit; and when the application programming interface is called in response to the user setting the flag bit of the second parameter to enable and initiating a data request instruction, it is called accordingly and calls the second state management unit, and changes the state of the second state management unit; the data request and state processing module 620 can also be used to send a data request message to the server based on the input parameter in response to the change of the state of the second state management unit.
[0093] In an exemplary embodiment of the present disclosure, when the flag bit of the second parameter is set to enabled, the data request and status processing module 620 can also be used to respond to a timed acquisition instruction initiated by a user and send a data request message to the server at a preset time interval.
[0094] In an exemplary embodiment of the present disclosure, the input parameters include input parameters of a function type, and the parameter input and processing module 610 can also be used to receive input parameters of the function type input by a user and execute a corresponding function, and determine the input parameters based on the result of executing the corresponding function.
[0095] In an exemplary embodiment of the present disclosure, the input parameters also include default parameters, and the parameter input and processing module 610 can also be used to merge the result of executing the corresponding function with the default parameters to determine the input parameters.
[0096] In an exemplary embodiment of the present disclosure, after sending a data request message to the server side, the data request and status processing module 620 can also be used to obtain the status of the data request from the server side; when the status of the data request is successful, the success status and the data received from the server side are fed back to the user; when the status of the data request is failed, the failure status is fed back to the user.
[0097] In an exemplary embodiment of the present disclosure, the hot update module 630 can also be used to call a third state management unit and set the data received from the server side as the value of the third state management unit, and set one or more program components to be associated with the third state management unit through the hot update program; and to update the values of corresponding parameters in the one or more program components according to the changed value of the third state management unit when the value of the third state management unit changes.
[0098] The specific details of each module or unit in the above data acquisition system have been described in detail in the corresponding data acquisition method, so they will not be repeated here.
[0099] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure is shown.
[0100] It should be noted that Figure 7 The computer system 700 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0101] like Figure 7 As shown, computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. Various programs and data required for system operation are also stored in RAM 703. CPU 701, ROM 702 and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to bus 704.
[0102] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT) display, a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0103] In particular, according to an embodiment of the present disclosure, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 709, and / or installed from a removable medium 711. When the computer program is executed by a central processing unit (CPU) 701, various functions defined in the method and apparatus of the present application are executed.
[0104] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.
[0105] It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0106] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0107] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data acquisition method, applied to a terminal device, characterized in that: include: Determine an input parameter input by a user, and set the value of the input parameter to the value of a first parameter of an application programming interface of the hot update program; In response to a data request instruction initiated by a user, calling the application programming interface to call the hot update program; Calling a preset first state management unit through the hot update program, and setting the first parameter to be associated with the first state management unit; comparing the value of the first parameter with the value of the first state management unit; When the value of the first parameter is different from the value of the first state management unit, updating the value of the first state management unit according to the value of the first parameter, and sending a data request message to the server based on the input parameter; When the value of the first parameter is the same as the value of the first state management unit, the data request message is not sent to the server.
2. The data acquisition method according to claim 1, characterized in that: The method further comprises: Setting the second parameter of the application programming interface to be associated with a preset second state management unit through the hot update program; In response to the user setting the flag bit of the second parameter to enable and initiating a data request instruction, calling the application programming interface to call the hot update program; calling the second state management unit through the hot update program, and changing the state of the second state management unit; and In response to the change of the state of the second state management unit, a data request message is sent to the server based on the input parameter.
3. The data acquisition method according to claim 2, characterized in that: The method further comprises: When the flag bit of the second parameter is set to enabled, in response to a timed acquisition instruction initiated by a user, a data request message is sent to the server at a preset time interval.
4. The data acquisition method according to claim 1, characterized in that: The input parameters include function type input parameters, and the input parameters input by the user are determined, including: An input parameter of the function type input by a user is received and a corresponding function is executed, and the input parameter is determined according to a result of executing the corresponding function.
5. The data acquisition method according to claim 4, characterized in that: The input parameters also include default parameters, and the step of determining the input parameters according to the result of executing the corresponding function includes: The result of executing the corresponding function is combined with the default parameter to determine the input parameter.
6. The data acquisition method according to any one of claims 1 to 3, characterized in that: After sending the data request message to the server, the method further includes: Obtaining the status of the data request from the server; When the data request status is successful, feeding back the success status and the data received from the server to the user; When the status of the data request is failure, the failure status is fed back to the user.
7. The data acquisition method according to claim 6, characterized in that: The method further comprises: Calling a preset third state management unit through the thermal update program and setting the data received from the server as a value of the third state management unit, and setting one or more program components to be associated with the third state management unit through the thermal update program; When the value of the third state management unit changes, the values of corresponding parameters in the one or more program components are updated according to the changed value of the third state management unit.
8. A data acquisition system, characterized in that: include: A parameter input and processing module, used to determine the input parameters input by the user; A hot update module, configured to set the value of the input parameter to the value of a first parameter of an application programming interface of the hot update module; and for, when the application programming interface is called in response to a data request instruction initiated by a user, being called accordingly and calling a preset first state management unit, and setting the first parameter to be associated with the first state management unit; A data request and status processing module is used to compare the value of the first parameter with the value of the first status management unit; when the value of the first parameter is different from the value of the first status management unit, the value of the first status management unit is updated according to the value of the first parameter, and a data request message is sent to the server based on the input parameter; when the value of the first parameter is the same as the value of the first status management unit, the data request message is not sent to the server.
9. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the data acquisition method according to any one of claims 1 to 7 based on instructions stored in the memory.
10. A computer-readable storage medium having a program stored thereon, wherein when the program is executed by a processor, the data acquisition method according to any one of claims 1 to 7 is implemented.
