Session updating method and storage mediumTechnical Field
The invention relates to the field of IM projects, in particular to a session updating method and a storage medium.
Background
Today, most mobile phone APPs provide message pushing functions, such as hot news recommendation of news clients, chat message reminding of IM tools, e-commerce product promotion information, notification and approval processes of enterprise applications, and the like. The push plays an important role in improving the activity of products, the utilization rate of functional modules, the viscosity of users and the retention rate of users.
Many IM software have the capability of a personal conversation list. The personal conversation list refers to a list of sending and receiving messages between a person and other people, and each record in the conversation list is a chat record of the person and other people and comprises person and group chatting. Say a chats with both B and C, and the chat time of C is updated, the order of the session list is C, B. If there is still a group chat D time update at this time, the order of the session list is D, C, B.
In order to achieve the above-mentioned effect of automatically updating the conversation ranking according to the chat time, a general system is to synchronously update information to the personal conversation list asynchronously every time a personal message or a group chat message is sent. In this scenario, if there are 1000 people in a group when group chat is performed, the personal conversation list information of the 1000 people needs to be modified each time a group message is sent, which may cause a large stress on the system and the database.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the session updating method and the storage medium are provided, so that the times of writing the database are greatly reduced, and the pressure of a system and the database is effectively relieved.
In order to solve the technical problems, the invention adopts the technical scheme that:
a method of session update, comprising:
when a consumer program acquires a group of messages from an MQ, asynchronously storing a group ID of the group of messages into a data structure of a local memory;
scanning the data structure at regular time, sending the scanned group ID to a corresponding consumer program, and clearing the data structure after the scanning is finished;
and after receiving the group ID, the consumer program updates the conversation list sequence of the group member corresponding to the group ID.
The invention provides another technical scheme as follows:
a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, is able to carry out the steps included in the method for session update.
The invention has the beneficial effects that: and recording the group ID updated with the message in a specified data structure of a local memory, scanning the data structure at regular time, emptying and re-recording after the scanning is finished, and realizing the regular unified update of the group session sequencing. Compared with the prior art that a large amount of database writing operations need to be frequently executed due to real-time group session updating, the method and the device can greatly reduce the times of writing the database and effectively relieve the pressure of the system and the database.
Drawings
Fig. 1 is a flowchart illustrating a session update method according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a session update method according to an embodiment of the present invention.
Detailed Description
In order to explain technical contents, achieved objects, and effects of the present invention in detail, the following description is made with reference to the accompanying drawings in combination with the embodiments.
The most key concept of the invention is as follows: and recording the group ID updated with the message in a specified data structure of a local memory, scanning the data structure at regular time, emptying and re-recording after the scanning is finished, and realizing the regular unified update of the group session sequencing.
Referring to fig. 1, the present invention provides a method for session update, including:
when a consumer program acquires a group of messages from an MQ, asynchronously storing a group ID of the group of messages into a data structure of a local memory;
scanning the data structure at regular time, sending the scanned group ID to a corresponding consumer program, and clearing the data structure after the scanning is finished;
and after receiving the group ID, the consumer program updates the conversation list sequence of the group member corresponding to the group ID.
Further, still include:
when a consumer program obtains a group of messages from the MQ, the group of messages is sent to the corresponding group members.
According to the above description, the group message is still updated normally in real time, and the immediacy of the message is ensured.
Further, the asynchronously storing the group ID of the group of messages into a data structure of a local memory specifically includes:
and storing the group ID of the group of messages as a key into a map data structure of a local memory through an asynchronous thread.
As can be seen from the above description, storing the identification information of the group whose message is updated in a map manner has the advantages of simple and clear structure, and being beneficial to the subsequent scanning operation.
Further, the updating of the session list ordering of the group members corresponding to the group ID specifically includes:
acquiring a session list of each group member of the group corresponding to the group ID;
and reordering the conversation list of each group member according to the currently acquired personal message and the group ID.
According to the description, the individual conversation and the group conversation are respectively obtained, the finally combined sequencing result is used as a display effect, and the accurate sequencing of the conversation list of the user can be ensured.
The invention provides another technical scheme as follows:
a computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, is adapted to carry out the steps of a method for session update comprising:
a method of session update, comprising:
when a consumer program acquires a group of messages from an MQ, asynchronously storing a group ID of the group of messages into a data structure of a local memory;
scanning the data structure at regular time, sending the scanned group ID to a corresponding consumer program, and clearing the data structure after the scanning is finished;
and after receiving the group ID, the consumer program updates the conversation list sequence of the group member corresponding to the group ID.
Wherein, still include:
when a consumer program obtains a group of messages from the MQ, the group of messages is sent to the corresponding group members.
Wherein the asynchronously storing the group ID of the group of messages into a data structure of a local memory specifically comprises:
and storing the group ID of the group of messages as a key into a map data structure of a local memory through an asynchronous thread.
Wherein, the updating of the session list ordering of the group members corresponding to the group ID specifically includes:
acquiring a session list of each group member of the group corresponding to the group ID;
and reordering the conversation list of each group member according to the currently acquired personal message and the group ID.
As can be understood from the above description, those skilled in the art can understand that all or part of the processes in the above technical solutions can be implemented by instructing related hardware through a computer program, where the program can be stored in a computer-readable storage medium, and when executed, the program can include the processes of the above methods. The program can also achieve advantageous effects corresponding to the respective methods after being executed by a processor.
The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
Example one
Referring to fig. 2, the present embodiment provides a method for optimizing a session update mode of an IM application, where the method includes:
s1: modifying the acquisition mode of the personal conversation list: distinguishing two types of personal conversation and group conversation in the personal conversation list;
correspondingly, when data of the personal conversation list is acquired each time, data of the personal conversation type and data of the group conversation type need to be acquired respectively, and the acquired data and the data are returned after being merged.
S2: when a consumer program acquires a group of messages from an MQ, asynchronously storing a group ID of the group of messages into a data structure of a local memory;
specifically, after a person in a group sends a chat message, the group message is sent to MQ in advance; when the consumer program gets the group message from the MQ, the prior art will perform the following: 1. sending the group message to other members of the group; 2. the personal conversation list for each member of the group is updated asynchronously. In the present embodiment, however, the above "1" is executed, and thereafter, the "2" is not executed, but: the group ID corresponding to the group message is asynchronously stored in a data structure of the local memory, which can be understood as a designated storage location. It is understood that the group ID of the group in which the message is updated is recorded to a specified location in the local memory.
Preferably, the data structure is in the form of map, where the key corresponds to the group ID, and the corresponding value may not be set, or the corresponding message time may be set. That is, the data structure functions to store information of the group in which the message is updated.
That is, as long as someone sends a message in each group, in addition to synchronizing the message to the group session interfaces of other members in the group, the group ID of the group is also stored in the MAP data structure in the local memory, and keys are corresponding group IDs, and each time the key is covered by using put operation.
S3: scanning the data structure at regular time, sending the scanned group ID to a corresponding consumer program, and clearing the data structure after the scanning is finished;
specifically, another asynchronous thread scans the data structure every preset time period (e.g., 15 seconds), and sends the currently traversed key value, i.e., the group ID (asynchronous) to the consumer program by traversing the map data structure, and after all the key values are traversed, deletes the map data structure, i.e., clears all the key values, and returns to step S2.
S4: and after receiving the group ID, the consumer program updates the conversation list sequence of the group member corresponding to the group ID.
After the MQ consumer program receives the asynchronous message sent in the previous step, the session list of all group members is obtained according to the group ID recorded in the asynchronous message; then, corresponding to each group member, the data of the human conversation type and the group ID recorded in the asynchronous message (thus obtaining the data of the group conversation type) obtained in step S1 are reordered according to the obtained time and displayed.
Through the embodiment, the personal conversation lists of all group members which need to be updated synchronously each time of sending the group message are changed into the unified updating at intervals, so that the times of writing the database are greatly reduced, and the pressure of the system and the database is reduced.
Example two
This embodiment provides a specific application scenario corresponding to the first embodiment:
1. firstly, a personal session list acquisition mode needs to be correspondingly modified, personal sessions and group session types are distinguished in a personal session list, and personal session type data and group session type data need to be respectively acquired and finally merged and returned when the personal session list data is acquired.
2. When a person in a group sends a chat message, a group message is sent to MQ, and when a consumer program obtains the message, the old program does 2 things: one is to send this message to the people in the group; another is to update each person's personal conversation list asynchronously. Here, the second thing needs to be modified, each group retains one piece of information in the memory, the data structure in the memory is in a Map mode, the key is the corresponding group ID, and the value may not be set. The function of the in-memory data structure is to store the latest messaging group information.
3. Assuming that there are 3 clusters of A, B and C, the corresponding cluster IDs are 1, 2, and 3, respectively. When the message is sent in each group, the information is synchronously stored in the MAP data structure in the local memory, the keys are the corresponding group IDs respectively, and the covering is carried out by using put operation each time.
4. There is an asynchronous thread that scans the MAP structure in local memory at regular intervals. The time interval may be determined according to a specific service. We assume this to be 15 seconds. The asynchronous thread loops through the data structure in the MAP, and sends an asynchronous message as long as the MAP has the group ID of the information. The message content is the group ID. And after all data information in the MAP is traversed, deleting the MAP structure, and performing the next cycle of writing operation in step 3.
5. When the MQ consumer receives the asynchronous message in step 4, the consumer thread acquires the session list information of all the members of the group and performs an update operation at the same time.
Since the session list of the group is updated periodically, the order of the session list of the group can only be guaranteed to a certain extent, and the data of the group session type acquired in step 1 still needs to be reordered, originally, the personal session data and the group session data in step 1 need to be reordered and displayed, so the final ordering is achieved by reordering after the data are merged in step 1.
By the method, the personal conversation chat list needs to be updated every time group sending information is changed into the personal conversation chat list only needs to be updated once every a period of time, so that the times of writing the database are greatly reduced, and the pressure between the system and the database is reduced.
EXAMPLE III
This embodiment corresponds to the first embodiment and the second embodiment, and provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, is capable of implementing the steps included in the session update method. The detailed steps are not repeated here, and refer to the descriptions of the first embodiment and the second embodiment for details.
In summary, the session update method and the storage medium provided by the invention greatly reduce the times of writing the database and effectively relieve the pressure of the system and the database in a manner of regularly and uniformly updating the group session; meanwhile, the session list still has higher timeliness, and the instant updating effect of the group message is not influenced; furthermore, the invention has the advantages of simple implementation mode, little memory resource occupation, high practicability and the like.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.