Data synchronization method, device, electronic device and storage medium

By configuring the SDK in the application to receive server-side change data and updating the local offline database, the problem of data synchronization complexity in the real-time database is solved, efficient data synchronization is achieved, and network interaction pressure is reduced.

CN114138801BActive Publication Date: 2025-05-23GUANG DONG MING CHUANG SOFTWARE TECH CORP
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111435626.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-29
Publication Date
2025-05-23
Estimated Expiration
2041-11-29

AI Technical Summary

Technical Problem

When the prior art realizes data synchronization in real-time databases, subscription listening information is required to store both the client and the server, resulting in an increase in the complexity of data synchronization.

Method used

By configuring the SDK in the application, receiving the change data sent by the server, updating the local offline database, and instructing the application to obtain data from the updated local offline database, thereby achieving data synchronization.

Benefits of technology

It reduces the complexity of data synchronization, reduces the direct interaction between applications and servers, alleviates network traffic pressure, and can still provide services normally in weak or networkless environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138801B_ABST
    Figure CN114138801B_ABST
Patent Text Reader

Abstract

The present application discloses a data synchronization method, device, electronic device and storage medium, and relates to the field of data processing technology. The method comprises: an SDK configured in an application receives change data sent by a server, and the change data is change data of a database corresponding to the application stored on the server; based on the change data, a local offline database set by the SDK is updated to obtain a local offline database after the data is updated; and the application is instructed to obtain data from the local offline database after the data is updated. The method enables the application to obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, thereby reducing the complexity of data synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and more specifically, to a data synchronization method, device, electronic device and storage medium. Background Art

[0002] A real-time database is a database built using a real-time data model, which is used to process rapidly changing data that is constantly updated and transactions with time limits. In the related methods of realizing data synchronization through a real-time database, it is necessary to store the subscription monitoring information of the client application on both the client and the server. Therefore, when switching the monitoring data, it is necessary to synchronously modify the subscription information of the client and the server, which increases the complexity of data synchronization. Summary of the invention

[0003] The present application proposes a data synchronization method, device, electronic device and storage medium to improve the above-mentioned problems.

[0004] In a first aspect, an embodiment of the present application provides a data synchronization method, which is applied to an SDK configured in an application, wherein the SDK is provided with a local offline database, and the method comprises: the SDK receives change data sent by a server, wherein the change data is change data of a database corresponding to the application stored on the server; the local offline database is updated based on the change data to obtain a local offline database after the data is updated; and the application is instructed to obtain data from the local offline database after the data is updated.

[0005] In the second aspect, an embodiment of the present application provides a data synchronization method, which is applied to a server, and the method includes: the server sends change data to the SDK configured in the application, and the change data is change data of a database corresponding to the application stored in the server, so that the SDK updates the local offline database set by the SDK based on the change data, obtains the local offline database after the data is updated, and the SDK instructs the application to obtain data from the local offline database after the data is updated.

[0006] In the third aspect, an embodiment of the present application provides a data synchronization device, which runs on an SDK configured in an application, and the SDK is provided with a local offline database, and the device comprises: a data receiving module, used for the SDK to receive change data sent by a server, and the change data is change data of a database corresponding to the application stored on the server; a data update module, used to update the local offline database based on the change data to obtain a local offline database after the data is updated; and a data synchronization module, used to instruct the application to obtain data from the local offline database after the data is updated.

[0007] In a fourth aspect, an embodiment of the present application provides a data synchronization device, which runs on a server, and the device includes: a data synchronization unit, which is used for the server to send change data to the SDK configured in the application, and the change data is change data of a database corresponding to the application stored on the server, so that the SDK updates the local offline database set by the SDK based on the change data, obtains the local offline database after the data is updated, and the SDK instructs the application to obtain data from the local offline database after the data is updated.

[0008] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a memory; one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute the data synchronization method provided in the first aspect or the data synchronization method provided in the second aspect.

[0009] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored. The program code can be called by a processor to execute the data synchronization method provided in the first aspect or the data synchronization method provided in the second aspect.

[0010] The present application provides a data synchronization method, device, electronic device and storage medium. The method is applied to an SDK configured in an application, and the SDK is provided with a local offline database. The method receives change data sent by a server through the SDK, and the change data is the change data of the database corresponding to the application stored on the server; then the local offline database is updated based on the change data to obtain the local offline database after the data is updated; and then the application is instructed to obtain data from the local offline database after the data is updated. Thus, the above method enables the application to obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, thereby reducing the complexity of data synchronization. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0012] Figure 1 A flow chart of a data synchronization method provided by an embodiment of the present application is shown.

[0013] Figure 2 A flow chart of a data synchronization method provided by another embodiment of the present application is shown.

[0014] Figure 3 A system architecture diagram showing data interaction between the SDK configured in the application provided in an embodiment of the present application and the server.

[0015] Figure 4 A flow chart of a data synchronization method provided by yet another embodiment of the present application is shown.

[0016] Figure 5 Shows Figure 4 Flow chart of the method for step S310 in .

[0017] Figure 6 A structural block diagram of a data synchronization device provided in an embodiment of the present application is shown.

[0018] Figure 7 A structural block diagram of a data synchronization device provided in another embodiment of the present application is shown.

[0019] Figure 8 A structural block diagram of an electronic device provided in an embodiment of the present application is shown.

[0020] Fig. 9 A storage unit for storing or carrying program codes for implementing a data synchronization method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0021] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0022] For ease of understanding, the nouns involved in the embodiments of the present application are briefly described below.

[0023] (1) MongoDB

[0024] MongoDB is a database based on distributed file storage. It is written in C++ and is designed to provide a scalable, high-performance data storage solution for WEB applications.

[0025] (2) Real Time Database

[0026] A real-time database is a database built using a real-time data model, which is used to process rapidly changing data that is constantly updated and time-limited transactions.

[0027] (3) Redis

[0028] Redis is an open source, network-enabled, memory-based, distributed, and optionally persistent key-value storage database written in ANSI C.

[0029] (4)Memcached

[0030] Memcached is a free, open source, high-performance, distributed memory object caching system. It is a memory-based key-value storage used to store small blocks of arbitrary data (strings, objects).

[0031] (5) Software Development Kit (SDK)

[0032] Refers to a collection of development tools used by software engineers to create application software for specific software packages, software frameworks, hardware platforms, operating systems, etc.

[0033] Data synchronization refers to the ability of a handheld computer to quickly synchronize data and share information with a desktop computer or laptop computer, so that the data remains complete and unified. Data synchronization is achieved through various data transmission interfaces, such as USB synchronization docks. With the development of information technology, many industries have higher and higher requirements for the real-time, high efficiency, and comprehensiveness of data information processing (such as data synchronization). Therefore, data synchronization is no longer a simple synchronization of internal and external storage, but requires a more real-time and efficient data synchronization solution.

[0034] In order to solve the above problems, in the relevant data synchronization solutions, Memcached or Redis can be used for data storage to achieve data synchronization, or the server can be used to notify the synchronization data to achieve data synchronization.

[0035] However, the inventors found that the solution of using Memcached or Redis for data storage to achieve data synchronization is relatively limited and has low efficiency when achieving data synchronization of large amounts of complex content; and the solution of using server-side notification to synchronize data to achieve data synchronization, although it solves the problem of the existing subscription-publish mechanism generating a large amount of redundant data on the server occupying system resources, stores a large number of subscription and publishing messages in the server-side subscription module. When switching to monitor data, it is necessary to synchronously modify the subscription information of the SDK and the server, which increases the complexity of data synchronization.

[0036] Therefore, in order to improve the above-mentioned problems, the inventors have conducted a long period of research and proposed the data synchronization method, device, electronic device and storage medium provided in the embodiments of the present application. The change data sent by the server is received through the SDK, and the change data is the change data of the database corresponding to the application stored on the server; then the local offline database is updated based on the change data to obtain the local offline database after the data is updated; then the application is instructed to obtain data from the local offline database after the data is updated. Therefore, through the above-mentioned method, the application can obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, thereby reducing the complexity of data synchronization.

[0037] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0038] See also Figure 1 , shows a flow chart of a data synchronization method provided by an embodiment of the present application, and this embodiment provides a data synchronization method, which can be applied to an SDK configured in an application, and the SDK is provided with a local offline database. The method includes:

[0039] Step S110: the SDK receives the change data sent by the server, where the change data is the change data of the database corresponding to the application program and stored on the server.

[0040] The application in this embodiment may be an Android application or an iOS application, and the specific type of the application may not be limited. Optionally, the application may be a system application or a third-party application installed on the electronic device.

[0041] As a method, the running data of the application may be stored locally and on the server side respectively. When the running data of the application is stored on the server side, the running data of the application may be stored in a database corresponding to the application.

[0042] Taking into account the impact of changes in the network environment on data synchronization, when storing the running data of the application locally, the running data of the application can be stored in the form of a local offline database. As an implementation method, the SDK can transmit the associated information of the application to the server, and the associated information may include the identifier of the application (the identifier can be used to uniquely identify the application), the application package name, the application login account, etc., so that the server can determine whether the application has the authority to access the database corresponding to the application stored on the server based on the associated information; if the application has the authority to access the database, then the SDK can establish a long connection channel with the server, and pull the associated data of the application from the server through the long connection channel to generate a local offline database. Among them, the associated data can be understood as the running data of the application.

[0043] It is understandable that when the network status is normal, the running data stored by the application locally and the running data stored by the application on the server can be the same; however, in some weak network or no network environment, the running data stored by the application on the server may not be synchronized locally, or when the user changes the electronic device used to log in to the application, the running data stored by the application on the server cannot be synchronized locally, which may affect the user's normal use of the application. At the same time, it also increases the difficulty and complexity of data synchronization to a certain extent.

[0044] In order to optimize the above problem, in this embodiment, the SDK configured in the application can receive the change data sent by the server, and the change data is the change data of the database corresponding to the application stored on the server. In one embodiment, the SDK can send a change data acquisition instruction to the server when the application is restarted or re-logged in, so that the server can search and return the change data of the database corresponding to the application based on the change data acquisition instruction. In this way, the SDK can receive the change data sent by the server.

[0045] In another implementation, the server can detect the login environment of the application (which can be understood as the login IP of the application). If it detects that the login environment of the application has changed, it can actively send the change data of the database corresponding to the application to the SDK. Alternatively, the server can detect the network signal strength of the electronic device where the application is located. If the network signal strength is lower than a preset threshold (the specific value can be set according to actual needs), it can actively send the change data of the database corresponding to the application to the SDK, so that the SDK receives the change data sent by the server.

[0046] Step S120: updating the local offline database based on the changed data to obtain a local offline database after data update.

[0047] As a method, after receiving the change data of the database corresponding to the application stored on the server, the local offline database of the application can be updated based on the change data to obtain the local offline database with updated data.

[0048] Step S130: instructing the application to obtain data from the local offline database after the data is updated.

[0049] As a method, when the local offline database is updated, the SDK can send an update data acquisition instruction to the application, and the update data acquisition instruction is used to instruct the application to obtain data from the local offline database after the data is updated. Alternatively, when the local offline database is updated for the first time, the SDK can directly synchronize the update data to the application, and instruct the application to actively and regularly obtain data from the local offline database after the data is updated. By instructing the application to obtain data directly from the local offline database after the data is updated, the direct interaction between the application and the server is reduced, thereby reducing the complexity of data synchronization. Compared with the case where the SDK has already obtained the change data of the database corresponding to the application, the embodiment of the present application does not require the application to interact directly with the server, which alleviates the pressure on network traffic. In addition, by instructing the application to obtain data from the local offline database, it can be achieved that services can be provided normally in a weak network or even no network environment.

[0050] The data synchronization method provided in this embodiment receives the change data sent by the server through the SDK, and the change data is the change data of the database corresponding to the application stored in the server; then updates the local offline database based on the change data to obtain the local offline database after the data is updated; and then instructs the application to obtain data from the local offline database after the data is updated. Thus, through the above method, the application can obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, reducing the complexity of data synchronization.

[0051] See also Figure 2 , shows a flow chart of a data synchronization method provided by another embodiment of the present application. This embodiment provides a data synchronization method, which can be applied to an SDK configured in an application, wherein the SDK is provided with a local offline database, and the method comprises:

[0052] Step S210: Obtaining operation instructions for the database.

[0053] In this implementation, the operation instruction may include a query instruction or a modification instruction.

[0054] As a method, when a user needs to operate a database corresponding to an application stored on the server, the application can be used to trigger the generation of an operation instruction. In this way, the SDK can obtain the operation instruction for the database from the application.

[0055] Step S220: Send the operation instruction to the server, so that the server performs corresponding operations on the database corresponding to the application according to the operation instruction.

[0056] Among them, after the SDK sends the above operation instruction to the server, the server can first perform authentication according to the permission rule file pre-set by the user in the background, that is, determine whether the current application has the permission to operate the database corresponding to the application stored on the server. Optionally, if it is determined that the current application has the permission to operate the database corresponding to the application stored on the server, it is deemed to have passed the authentication, and the server can execute the operation instruction; if it is determined that the current application does not have the permission to operate the database corresponding to the application stored on the server, it is deemed to have failed the authentication, and the server can return the authentication failure information to the SDK.

[0057] The above authentication process is described below with reference to the accompanying drawings:

[0058] See also Figure 3 , shows a system architecture diagram of data interaction between the SDK configured in the application provided in the embodiment of the present application and the server. Figure 3 As shown, the SDK configured in the client (which can also be understood as the aforementioned application) interacts with the server through the long connection middleware. The server can provide real-time database services. The server includes a connection management module (Connection Manager), a data processing module (Data Manager) and an authority module (AuthorityModel).

[0059] When the application accesses the real-time database service of the server, a pair of AppKey (which can be understood as the application account in this embodiment) and AppSecret (which can be understood as the application password) can be obtained in the background of the server, where AppKey uniquely corresponds to a background database. The SDK can generate a signature (Sign) based on the application's identification, application package name, application login account and other information and AppKey and AppSecret according to the agreed algorithm, and then pass the above application's identification, application package name, application login account and other information, AppKey and Sign as parameters to the server's permission module for authentication.

[0060] The permission module on the server side determines whether the application has the permission to access the database corresponding to the application stored on the server side according to the above parameters transmitted by the SDK (the first authentication on the server side). If it is determined that the application has the permission to access the database corresponding to the application stored on the server side, the application identification, application package name, application login account and other information are recorded in the memory cache of the connection management module and stored in the database (i.e. Figure 3 If the application is determined to have no authority to access the database corresponding to the application stored on the server, the authentication failure information is returned to the SDK.

[0061] When the SDK accesses the real-time database service on the server side, it is necessary to pre-set the package name information of the application with database access rights in the background of the server side. When the application transmits the application identification, application package name, application login account and other information through the configured SDK, the permission verifier in the server side will first determine whether the application package name has been configured in the background. If not, the authentication will not pass; if it has been configured, the permission management module will obtain the AppSecret in the background according to the transmitted AppKey, and then generate the server verification signature according to the same algorithm as agreed above with the parameters transmitted by other SDKs, and then compare it with the signature Sign transmitted by the SDK (the second authentication in the server side). If the two signatures are consistent, the authentication is passed, that is, the server can allow the application to operate on the database. If the authentication fails, the authentication failure message will be returned to the SDK.

[0062] Among them, when the second authentication is passed, the server can use the MongoDB database to store the received operation instructions for the database. MongoDB stores data in JSON format, and the storage method is more flexible. Compared with the memory database, it supports more complex data expression, and the supported query and indexing methods are more flexible. It also supports features such as replication sets and automatic sharding. The cluster technology is mature, and it is superior to memory databases such as Redis and Memcached in terms of reliability and data volume.

[0063] Step S230: the SDK receives the change data of the database corresponding to the application after the corresponding operation sent by the server, and the change data is the change data of the database corresponding to the application stored in the server.

[0064] Among them, the operation instructions are different, and the change data of the database corresponding to the application program is different.

[0065] In one implementation, if the operation instruction is a modification instruction (which may include modification instructions such as adding or deleting), the SDK receives the change data of the database corresponding to the application after the corresponding operation sent by the server, which may include: the SDK receives the data synchronization instruction and modification path sent by the server, and the data synchronization instruction and modification path are determined based on the modification operation on the database corresponding to the application; based on the data synchronization instruction, a data query instruction is sent to the server to query the latest data corresponding to the modification path; the latest data returned by the server is received, and the latest data is used as the change data of the database corresponding to the application.

[0066] In a specific application scenario, such as Figure 3 As shown, if the operation instruction is a modification instruction, the server first determines whether there are other clients (i.e., the client logged in by the application) modifying the same data path at the same time. If so, it returns a failure message that it cannot be modified at the same time; if not, a distributed lock is added to the path to prevent other clients from modifying it. Then, after performing the corresponding modification operation, the data synchronization module in the data processing module returns the modification success information to the SDK, and asynchronously sends a synchronization instruction to all clients connected to this database to update the local offline database.

[0067] Among them, specific examples of the server returning the changed data of the database corresponding to the application to the SDK may include: ① After the server receives the modification instruction and executes it, it records the path information of the modified data, such as A->B->C; ② The server finds all client devices that have logged in (or have logged in) to the same account based on the application's identification, application package name, application login account and other information; ③ A data synchronization instruction is sent to all found client devices, and the operator bit in the data synchronization instruction indicates that data synchronization is required, and the previously recorded modified path is passed at the same time; ④ After the SDK receives the data synchronization instruction, it sends a query instruction to the server, and the query instruction is used to query the latest data of the path; ⑤ The server returns the latest data of the path to the SDK, and the SDK updates its own offline database based on the latest data to obtain the local offline database after the data is updated, thereby realizing data synchronization.

[0068] In another implementation, if the operation instruction is a query instruction, the SDK receives the change data of the database corresponding to the application after the corresponding operation sent by the server, which may include: the SDK receives the query result data sent by the server, and the query result data is obtained based on the query operation corresponding to the query instruction. After receiving the query result data, the SDK can actively synchronize the queried data to the application, or instruct the application to obtain it from the local offline database.

[0069] Step S240: updating the local offline database based on the changed data to obtain a local offline database after data update.

[0070] Step S250: instruct the application to obtain data from the local offline database after the data is updated.

[0071] The data synchronization method provided in this embodiment obtains the operation instruction for the database; then sends the operation instruction to the server, so that the server performs the corresponding operation on the database corresponding to the application according to the operation instruction; then receives the change data of the database corresponding to the application after the corresponding operation sent by the server; then updates the local offline database based on the change data to obtain the local offline database after the data is updated; then instructs the application to obtain data from the local offline database after the data is updated. Thus, the above method enables the application to obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, thereby reducing the complexity of data synchronization.

[0072] See also Figure 4 , shows a flow chart of a data synchronization method provided by another embodiment of the present application. This embodiment provides a data synchronization method that can be applied to a server. The method includes:

[0073] Step S310: The server sends change data to the SDK configured in the application, where the change data is change data of a database corresponding to the application stored in the server, so that the SDK updates the local offline database set by the SDK based on the change data, obtains the local offline database after the data is updated, and instructs the SDK to obtain data from the local offline database after the data is updated.

[0074] In this implementation, the server and the SDK are connected via a long connection channel. The specific implementation process of the server sending the change data to the SDK configured in the application can refer to the description in the above embodiment, which will not be repeated here.

[0075] See also Figure 5 As a method, step S310 may specifically include:

[0076] Step S311: The server receives an operation instruction sent by the SDK configured in the application.

[0077] As mentioned above, the operation instruction may include a modification instruction or a query instruction.

[0078] Step S312: performing corresponding operations on the database corresponding to the application according to the operation instruction to obtain operation result data.

[0079] As a method, performing corresponding operations on the database corresponding to the application according to the operating instructions may include: identifying whether the application has the authority to operate the database; if the application has the authority to operate the database, performing corresponding operations on the database corresponding to the application according to the operating instructions.

[0080] Step S313: Sending the operation result data to the SDK, wherein the operation result data is the change data of the database corresponding to the application.

[0081] The data synchronization method provided in this embodiment enables an application to obtain data from a local offline database to achieve data synchronization without the need for the application to directly interact with the server, thereby reducing the complexity of data synchronization.

[0082] See also Figure 6 , is a structural block diagram of a data synchronization device provided in an embodiment of the present application. This embodiment provides a data synchronization device 400, which can be run in an SDK configured in an application. The SDK is provided with a local offline database. The device 400 includes: a data receiving module 410, a data updating module 420, and a data synchronization module 430:

[0083] The data receiving module 410 is used for the SDK to receive the change data sent by the server, where the change data is the change data of the database corresponding to the application program stored in the server.

[0084] As a method, the device 400 may also include an instruction acquisition module and an instruction receiving module, wherein the instruction acquisition module is used to acquire an operation instruction for the database before the SDK receives the change data sent by the server; the instruction receiving module is used to send the operation instruction to the server, so that the server performs a corresponding operation on the database corresponding to the application according to the operation instruction. In this way, the data receiving module 410 can be used for the SDK to receive the change data of the database corresponding to the application after the corresponding operation sent by the server.

[0085] As an implementation mode, if the operation instruction is a modification instruction, the SDK receives the change data of the database corresponding to the application after the corresponding operation is sent by the server, which may include: the SDK receives the data synchronization instruction and the modification path sent by the server, and the data synchronization instruction and the modification path are determined based on the modification operation on the database corresponding to the application; based on the data synchronization instruction, a data query instruction is sent to the server to query the latest data corresponding to the modification path; the latest data is received from the server, and the latest data is used as the change data of the database corresponding to the application.

[0086] As another implementation, if the operation instruction is a query instruction, the SDK receives the change data of the database corresponding to the application after the corresponding operation is sent by the server, which may include: the SDK receives the query result data sent by the server, and the query result data is obtained based on the query operation corresponding to the query instruction.

[0087] The data updating module 420 is used to update the local offline database based on the changed data to obtain the local offline database after the data is updated.

[0088] The data synchronization module 430 is used to instruct the application to obtain data from the local offline database after the data is updated.

[0089] Optionally, the device 400 may also include an offline database generation module, which is used by the SDK to transmit the associated information of the application to the server, so that the server determines whether the application has the permission to access the database based on the associated information; if the application has the permission to access the database, the SDK establishes a long connection channel with the server; and pulls the associated data of the application through the long connection channel to generate a local offline database.

[0090] See also Figure 7 , is a structural block diagram of a data synchronization device provided by another embodiment of the present application. This embodiment provides a data synchronization device 500, which can be run on a server. The device 500 includes: a data synchronization unit 510:

[0091] The data synchronization unit 510 is used for the server to send change data to the SDK configured in the application, where the change data is change data of the database corresponding to the application stored in the server, so that the SDK updates the local offline database set by the SDK based on the change data, obtains the local offline database after the data is updated, and instructs the SDK to obtain data from the local offline database after the data is updated.

[0092] In this embodiment, the server and the SDK may be connected via a long connection channel.

[0093] As a method, the data synchronization unit 510 can be specifically used for the server to receive operation instructions sent by the SDK configured in the application; perform corresponding operations on the database corresponding to the application according to the operation instructions to obtain operation result data; and send the operation result data to the SDK, wherein the operation result data is the change data of the database corresponding to the application.

[0094] Among them, performing corresponding operations on the database corresponding to the application according to the operating instructions may include: identifying whether the application has the authority to operate the database; if the application has the authority to operate the database, performing corresponding operations on the database corresponding to the application according to the operating instructions.

[0095] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0096] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.

[0097] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0098] See also Figure 8 Based on the above data synchronization method and device, the embodiment of the present application also provides an electronic device 100 that can execute the above data synchronization method. The electronic device 100 includes a memory 102 and one or more (only one is shown in the figure) processors 104 coupled to each other, and the memory 102 and the processor 104 are connected by a communication line. The memory 102 stores a program that can execute the content of the above embodiment, and the processor 104 can execute the program stored in the memory 102.

[0099] Among them, the processor 104 may include one or more processing cores. The processor 104 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 102, and calling data stored in the memory 102. Optionally, the processor 104 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 104 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 104, but may be implemented separately through a communication chip.

[0100] The memory 102 may include a random access memory (RAM) or a read-only memory (ROM). The memory 102 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 102 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the aforementioned embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device 100 during use.

[0101] Please refer to Fig. 9 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 600 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.

[0102] The computer readable storage medium 600 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 600 includes a non-transitory computer-readable storage medium. The computer readable storage medium 600 has storage space for program code 610 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 610 can be compressed, for example, in an appropriate form.

[0103] In summary, the data synchronization method, device, electronic device and storage medium provided in the embodiment of the present application receive the change data sent by the server through SDK, and the change data is the change data of the database corresponding to the application stored on the server; then update the local offline database based on the change data to obtain the local offline database after the data is updated; then instruct the application to obtain data from the local offline database after the data is updated. Thus, the above method enables the application to obtain data from the local offline database to achieve data synchronization without the need for the application to interact directly with the server, reducing the complexity of data synchronization.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements 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 the present application.

Claims

1. A data synchronization method, It is characterized in that The SDK configured in the application program of the electronic device is applied, and the SDK is provided with a local offline database. The method comprises: Obtaining operation instructions of the application program on a database in the server; Sending the operation instruction to the server, so that the server performs corresponding operations on the database corresponding to the application according to the operation instruction; The SDK receives the change data sent by the server, wherein the change data is the change data of the database corresponding to the application program stored in the server, and the change data is obtained after executing the operation instruction; Update the local offline database based on the changed data to obtain a local offline database after data update; Instructing the application to obtain data from the local offline database after the data is updated, so as to reduce direct interaction between the application and the server; The method further comprises: If the server detects that the login environment of the application has changed, it actively sends the changed data of the database corresponding to the application to the SDK.

2. The method according to claim 1, It is characterized in that If the operation instruction is a modification instruction, the method further includes: The SDK receives a data synchronization instruction and a modification path sent by the server, wherein the data synchronization instruction and the modification path are determined based on a modification operation on a database corresponding to the application; Sending a data query instruction to the server based on the data synchronization instruction to query the latest data corresponding to the modified path; The latest data returned by the server is received, and the latest data is used as the change data of the database corresponding to the application.

3. The method according to claim 1, It is characterized in that If the operation instruction is a query instruction, the method further includes: The SDK receives the query result data sent by the server, where the query result data is obtained based on the query operation corresponding to the query instruction.

4. The method according to claim 1, It is characterized in that The method further comprises: The SDK transmits the associated information of the application to the server, so that the server determines whether the application has the authority to access the database based on the associated information; If the application has permission to access the database, the SDK establishes a persistent connection channel with the server; Pull the associated data of the application through the long connection channel to generate a local offline database.

5. A data synchronization method, It is characterized in that Applied to the server, the method includes: The server receives an operation instruction sent by the SDK configured in the application, performs a corresponding operation on the database corresponding to the application according to the operation instruction, and obtains operation result data; Sending the operation result data to the SDK, wherein the operation result data is the change data of the database corresponding to the application, and the change data is the change data of the database corresponding to the application stored on the server, so that the SDK updates the local offline database set by the SDK based on the change data to obtain the local offline database after the data is updated, and the SDK instructs the application to obtain data from the local offline database after the data is updated, so as to reduce the direct interaction between the application and the server; The method further comprises: If the server detects that the login environment of the application has changed, it actively sends the changed data of the database corresponding to the application to the SDK.

6. The method according to claim 5, It is characterized in that The performing corresponding operations on the database corresponding to the application according to the operation instruction includes: Identifying whether the application has the authority to operate the database; If the application has the authority to operate the database, a corresponding operation is performed on the database corresponding to the application according to the operation instruction.

7. The method according to any one of claims 5 to 6, It is characterized in that The server and the SDK are connected via a long connection channel.

8. A data synchronization device, It is characterized in that An SDK configured in an application running in an electronic device, wherein the SDK is provided with a local offline database, and the device comprises: An instruction receiving module is used to obtain the operation instruction of the application program on the database in the server; send the operation instruction to the server, so that the server performs corresponding operations on the database corresponding to the application program according to the operation instruction; A data receiving module, used for the SDK to receive the change data sent by the server, wherein the change data is the change data of the database corresponding to the application program stored in the server, and the change data is obtained after executing the operation instruction; A data updating module, used to update the local offline database based on the changed data to obtain a local offline database after the data is updated; A data synchronization module, used to instruct the application to obtain data from the local offline database after the data is updated, so as to reduce the direct interaction between the application and the server; If the server detects that the login environment of the application has changed, it will actively send the change data of the database corresponding to the application to the SDK.

9. A data synchronization device, It is characterized in that Running on the server, the device includes: A data synchronization unit, configured to receive an operation instruction sent by the SDK configured in the application, perform a corresponding operation on the database corresponding to the application according to the operation instruction, obtain operation result data, and send the operation result data to the SDK, wherein the operation result data is change data of the database corresponding to the application, and the change data is change data of the database corresponding to the application stored on the server, so that the SDK updates the local offline database set by the SDK based on the change data, obtains the local offline database after the data is updated, and enables the SDK to instruct the application to obtain data from the local offline database after the data is updated, so as to reduce the direct interaction between the application and the server; The data synchronization unit is also used to actively send the changed data of the database corresponding to the application to the SDK if the server detects that the login environment of the application has changed.

10. An electronic device, It is characterized in that comprising one or more processors and memory; One or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method of any one of claims 1-4 or 5-7.

11. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 4 or 5 to 7 is executed.

Citation Information

Patent Citations

  • Network file system and method for accessing network file system

    CN103139224A

  • Database data synchronization method

    CN107704607A

  • Offline implementation method and apparatus of web application, computer device and storage medium

    CN109451064A