Message pulling method and device and electronic equipment

By caching message streams from the database into cache blocks and retrieving messages from the cache blocks when a message retrieval request is received, the problem of excessive database read pressure in enterprise instant messaging applications is solved, improving message retrieval efficiency and database load capacity.

CN122053550APending Publication Date: 2026-05-15TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411626023.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-14
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

In enterprise instant messaging applications, when multiple enterprise instant messaging clients pull messages from the database and synchronize them locally, it can cause excessive data reading pressure on the database, resulting in database overload.

Method used

The message stream stored in the database is divided into blocks according to the sequence number in ascending order. These blocks are then cached in multiple cache blocks. When a message retrieval request is received, the target cache block is determined by referring to the sequence number and the cache block. The message is then read from the cache block and returned, reducing the number of reads from the database.

Benefits of technology

It effectively reduces the database access pressure caused by repeatedly reading messages from the database, improves the message retrieval rate, and avoids database overload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122053550A_ABST
    Figure CN122053550A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to a message pulling method and device and electronic equipment.The method comprises the steps that a message pulling request is obtained, and the message pulling request comprises a starting sequence number of a request for pulling a message and the pulling number; based on the reference serial number and the minimum serial number of the message cached by each cache block in the cache, performing cache block query in the cache, and determining a target cache block; wherein the reference serial number is initialized as a starting serial number; reading a target number of messages of which the serial numbers are not smaller than the reference serial number and the serial numbers are minimum in the target cache block, and adding the read messages into a return data packet; wherein the target number does not exceed the pulling number; if the number of messages in the return data packet reaches the pulling number, sending the return data packet to the client; in the message pulling process, the message pulling request is to read the required message from the target cache block, so that the access to the database is avoided, and the access pressure of the database is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a message retrieval method, apparatus, and electronic device. Background Technology

[0002] In enterprise instant messaging applications, conversation messages created within an enterprise are stored in a database. After logging into the enterprise instant messaging client, the latest messages need to be read from the database to synchronize with the local enterprise instant messaging client. However, if there are many employees in the enterprise, multiple enterprise instant messaging clients may pull messages from the database to synchronize with their local machines, which can lead to excessive data reading pressure on the database and cause database overload. Summary of the Invention

[0003] In view of this, embodiments of this application propose a message retrieval method, apparatus, and electronic device to solve the problem of high database read pressure and database overload caused by the need to read messages stored in the data multiple times.

[0004] The embodiments of this application are implemented using the following technical solutions:

[0005] In a first aspect, embodiments of this application provide a message retrieval method, the method comprising: obtaining a message retrieval request from a client; the message retrieval request including a start sequence number and a retrieval quantity for a requested message; based on a reference sequence number and the minimum sequence number of messages cached in each cache block in the cache, performing a cache block query in the cache to determine a target cache block; the target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, the minimum sequence number not exceeding the reference sequence number; a cache block caches messages from a message block, the message block being determined by dividing a message stream stored in a database into blocks in ascending order of sequence number; the reference sequence number being initialized to the start sequence number; reading a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and adding the read messages to a return data packet for the message retrieval request; the target number not exceeding the retrieval quantity; if the number of messages in the return data packet reaches the retrieval quantity, sending the return data packet to the client.

[0006] Secondly, embodiments of this application provide a message retrieval device, comprising: an acquisition module, configured to acquire a message retrieval request from a client; the message retrieval request includes a start sequence number and a retrieval quantity for a requested message; a query module, configured to perform a cache block query in the cache based on a reference sequence number and the minimum sequence number of messages cached in each cache block in the cache, to determine a target cache block; the target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, the minimum sequence number not exceeding the reference sequence number; a cache block caches messages from a message block, the message block being determined by dividing a message stream stored in a database into blocks in ascending order of sequence number; the reference sequence number is initialized to the start sequence number; a reading module, configured to read a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and add the read messages to a return data packet for the message retrieval request; the target number does not exceed the retrieval quantity; and a response module, configured to send the return data packet to the client if the number of messages in the return data packet reaches the retrieval quantity.

[0007] In some embodiments, each cache block further stores a first field; the value of the first field in a cache block is used to indicate whether there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block; the message retrieval device further includes a judgment module, used to update the reference sequence number to the maximum sequence number of the cached message in the target cache block and update the target quantity to the difference between the retrieval quantity and the number of messages in the return data packet if the number of messages in the returned data packet does not reach the retrieval quantity and the retrieval condition is satisfied based on the value of the first field in the target cache block; a loop execution module is used to return to the step of performing the cache block query in the cache based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache to determine the target cache block; wherein, the retrieval condition includes a first condition, the first condition being that the value of the first field in the target cache block is a first value; wherein, when the value of the first field in a cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block.

[0008] In some implementations, the message retrieval device further includes an update module for incrementing the cumulative number of cache queries for the message retrieval request by 1; the continued retrieval condition further includes a second condition, which means that the number of cache queries for the message retrieval request is less than a threshold; the judgment module is specifically used to determine that the continued retrieval condition is met when the first condition is satisfied based on the value of the first field in the target cache block, and the second condition is satisfied based on the number of cache queries for the message retrieval request.

[0009] In some implementations, the response module is further configured to send the return data packet to the client if the number of messages in the returned data packet does not reach the fetch quantity and it is determined that either the first condition or the second condition is not met.

[0010] In some embodiments, the returned data packet further includes a first indicator field and a second indicator field; the message retrieval device further includes a first assignment module, configured to assign the first value to the first indicator field if the value of the first field in the last target cache block determined by querying for the message retrieval request is a first value, or if the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet; wherein, when the value of the first field in the last target cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block; and, if the value of the first field in the last target cache block is a second value, and The maximum sequence number of the message cached in the last target cache block is equal to the maximum message sequence number in the returned data packet, and the second value is assigned to the first indicator field; wherein, when the value of the first field in the last target cache block is the second value, it indicates that there is no message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block; the second assignment module is used to assign one of the maximum sequence number of the message cached in the last target cache block and the maximum message sequence number in the returned data packet to the second indicator field according to the value of the first field in the last target cache block; wherein, the value of the second indicator field is used to determine the start sequence number of the next request to fetch messages.

[0011] In some implementations, the second assignment module is specifically used to assign the maximum sequence number of the cached message in the last target cache block to the second indicator field if the value of the first field in the last target cache block is a first value and the maximum sequence number of the cached message in the last target cache block is equal to the maximum message sequence number in the returned data packet; and if the value of the first field in the last target cache block is a second value, or the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet, the minimum value between the maximum sequence number of the cached message in the last target cache block and the maximum message sequence number in the returned data packet is assigned to the second indicator field.

[0012] In some implementations, the acquisition module is further configured to receive a re-message retrieval request sent by the client, wherein the start sequence number in the re-message retrieval request is equal to the sum of the value of the second indicator field in the returned data and 1; the re-message retrieval request is sent by the client after detecting that the value of the first indicator field in the returned data packet is a first value.

[0013] In some implementations, the message retrieval device further includes a cache status judgment module for obtaining valid status information of the target cache block; and a cache update module for requesting the database to sequentially read a reference number of messages with a sequence number not less than the minimum sequence number corresponding to the target cache block in the message stream if the valid status information indicates that the target cache block has expired, based on the minimum sequence number corresponding to the target cache block, and caching the read messages in the target cache block; the reference number is the maximum number of messages that the target cache block is allowed to cache.

[0014] In some implementations, the message retrieval request further includes a target message stream identifier of the target message stream to which the requested message belongs; the message retrieval device further includes a cache determination module, configured to determine whether the message requested by the message retrieval request is located in the cache based on the message stream identifier and the start sequence number in the message retrieval request, as well as the message stream identifier and the corresponding minimum sequence number of the message cached in each cache block in the cache; the query module is further configured to, if it is determined that the message requested by the message retrieval request is located in the cache, perform a cache block query in the cache based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache, to determine the target cache block.

[0015] In some implementations, the client is an enterprise instant messaging client, the message stream is an enterprise message stream, and the message retrieval request includes the enterprise identifier to which the client belongs; the query module is further configured to perform a cache block query in the cache associated with the enterprise identifier based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache associated with the enterprise identifier, and determine the target cache block.

[0016] Thirdly, embodiments of this application provide an electronic device, including: a processor; and a memory storing computer instructions, which, when executed by the processor, implement the above-described method.

[0017] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the above-described method.

[0018] Fifthly, embodiments of this application provide a computer program product, including computer instructions, characterized in that, when the computer instructions are executed by a processor, they implement the above-described method.

[0019] This application provides a message retrieval method, apparatus, and electronic device. The method involves dividing a message stream stored in a database into blocks according to ascending sequence numbers, and caching these blocks into multiple cache blocks. Upon receiving a message retrieval request, a reference sequence number is initialized to the start sequence number in the request. Then, based on the reference sequence number and the minimum sequence number of messages cached in each cache block, a target cache block is determined with the minimum sequence number less than the reference sequence number and the smallest sequence number interval between the minimum and reference sequence numbers. A target number of messages with sequence numbers not less than the reference sequence number and the smallest sequence number are read from this target cache block, and the read messages are added to the return data packet for the message retrieval request. If the number of messages in the return data packet reaches the required number to be retrieved... A return data packet is sent to the client; this allows messages to be read from the buffer block and returned to the client without needing to read messages from the database. When faced with multiple message retrieval requests simultaneously, each message retrieval request will determine its corresponding target buffer block based on its different start sequence number, and read messages from the corresponding target buffer block. This allows multiple message retrieval requests to read the required messages from different target buffer blocks. In other words, the pressure of reading messages from the database can be distributed across multiple buffer blocks. Moreover, reading from the cache is faster than reading from the database, which can improve the message retrieval rate. Therefore, it can effectively reduce the problem of high database access pressure caused by needing to read messages from the database multiple times, and avoid database overload.

[0020] These or other aspects of this application will become more apparent in the following description of the embodiments. Attached Figure Description

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

[0022] Figure 1A A schematic diagram of an application scenario involving an embodiment of this application is shown.

[0023] Figure 1B This illustration shows a schematic diagram of a message stream being cached in chunks according to an embodiment of this application.

[0024] Figure 2 The diagram shows a first flowchart of a message retrieval method provided in an embodiment of this application.

[0025] Figure 3 This illustration shows a second flowchart of a message retrieval method provided in an embodiment of this application.

[0026] Figure 4 The diagram shows a third flowchart of a message retrieval method according to an embodiment of this application.

[0027] Figure 5 The diagram shows a fourth flowchart of a message retrieval method provided in an embodiment of this application.

[0028] Figure 6 A schematic diagram of message retrieval according to another embodiment of this application is shown.

[0029] Figure 7 A schematic diagram of the structure of a message retrieval device provided in an embodiment of this application is shown.

[0030] Figure 8 A schematic diagram of an electronic device provided in one embodiment of this application is shown. Detailed Implementation

[0031] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0032] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative effort are within the scope of protection of the present application.

[0033] In the following description, the terms "first" and "second" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first" and "second" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0034] In this document, "multiple" refers to two or more. "And / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following associated objects are in an "or" relationship. In the following description, references to "some embodiments or some embodiment methods" describe a subset of all possible embodiments. However, it is understood that "some embodiments" can be the same subset or different subsets of all possible embodiments and can be combined with each other without conflict.

[0035] To facilitate understanding of this application, some terms will be explained below.

[0036] A message stream is a collection of messages organized according to their sequence numbers. For example, messages can be arranged in ascending order of their sequence numbers to form a message stream. In instant messaging applications, each user has a corresponding message stream, which includes all the messages received by that user. Message streams can be stored using key-value pairs. For instance, the key of a user's message stream is the user identifier, and the value is all the messages in the stream.

[0037] Message sequence number: Also known as message sequence number, each message in the message stream has a corresponding sequence number. The sequence number is not necessarily consecutive, but it is monotonically increasing. The message sequence number can be assigned according to the time when the message was generated. The sequence number assigned to the message generated earlier is less than the sequence number assigned to the message generated later.

[0038] Cache: refers to a storage device that enables high-speed data exchange. A cache can be divided into multiple cache blocks.

[0039] In enterprise instant messaging applications, conversation messages created within an enterprise are stored in a database. After logging into the enterprise instant messaging client, the latest messages need to be read from the database to synchronize with the local enterprise instant messaging client. However, if there are many employees in the enterprise, multiple enterprise instant messaging clients may pull messages from the database to synchronize with their local machines, which can lead to excessive data reading pressure on the database and cause database overload.

[0040] To address the aforementioned problems, this application proposes a message retrieval method, apparatus, and electronic device.

[0041] Please see Figure 1A , Figure 1A The application scenario diagram of the present application embodiment is shown, including terminal 10 and server 20, which are connected via wired or wireless network.

[0042] Terminal 10 may have a client installed, through which messages can be sent or received, thereby enabling communication with other clients. Server 20 may have a database deployed, which can store multiple message streams. Server 20 also has a cache, which can cache all or part of the message streams stored in the database in blocks.

[0043] In some embodiments, all messages in the message stream can be divided into blocks according to their sequence numbers in ascending order to obtain multiple message blocks. For any two message blocks, the sequence numbers of the messages in one message block are either all greater than the sequence numbers of the messages in the other message block, or both are less than the sequence numbers of the messages in the other message block.

[0044] Figure 1B This example illustrates a block-based cache of message streams stored in a database. Figure 1B In this implementation, the message stream includes messages with sequence numbers 1-15. It's worth noting that in other embodiments, the sequence numbers of adjacent messages in the message stream are not necessarily consecutive. The messages with sequence numbers 1-15 in the message stream are divided into three message blocks in ascending order of sequence number: message block A1, message block A2, and message block A3. Message block A1 includes messages with sequence numbers 1-5, message block A2 includes messages with sequence numbers 6-10, and message block A3 includes messages with sequence numbers 11-15. Then, message blocks A1, A2, and A3 are cached in multiple cache blocks; specifically, message block A1 is cached in cache block B1, message block A2 in cache block B2, and message block A3 in cache block B3.

[0045] In this way, since messages in the message stream of the database are cached in the cache, the speed of reading messages from the cache is higher than the speed of reading messages from the database. Subsequently, if a message retrieval request is received, messages can be read from each cache block in the cache, thereby reducing the number of times messages are read from the database, thus improving message retrieval efficiency. Especially when multiple clients need to retrieve some or the exact same messages, retrieving messages from the cache is faster than retrieving messages from the database, and can significantly reduce the data reading pressure on the database.

[0046] Terminal 10 sends a message retrieval request to server 20 via a client. The message retrieval request includes the start sequence number and the number of messages to be retrieved. After receiving the message retrieval request from the client, server 20 initializes the reference sequence number to the start sequence number in the message retrieval request. Then, based on the reference sequence number and the minimum sequence number of messages cached in each cache block in the cache, it performs a cache block lookup in the cache to determine the target cache block. The target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, and the minimum sequence number corresponding to the target cache block does not exceed the reference sequence number. The target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number are read from the target cache block, and the read messages are added to the return data packet for the message retrieval request. The target number does not exceed the retrieval number. If the number of messages in the return data packet reaches the retrieval number, a return data packet is sent to the client.

[0047] continue Figure 1B For example, if server 20 receives message retrieval request Q1, and the start sequence number in message retrieval request Q1 is 1 and the number of messages to be retrieved is 5, that is, message retrieval request Q1 requests to retrieve 5 messages starting from sequence number 1, in this case, by combining the start sequence number in message retrieval request Q1 and the minimum sequence number of the messages cached in each cache block, cache block A1 can be determined as the target cache block for message retrieval request Q1. Then, the messages requested by message retrieval request Q1 are retrieved from cache block A1.

[0048] In some embodiments, the message requested by the message fetch request may be located in multiple message blocks, thus requiring multiple determinations of the target cache block. Continue Figure 1B For example, if server 20 receives message retrieval request Q2, where the start sequence number is 7 and the number of messages to be retrieved is 8, combining the start sequence number in message retrieval request Q2 with the minimum sequence number of messages cached in each cache block, a target cache block for message retrieval request Q2 can be determined as cache block A2. Then, messages with sequence numbers 7-10 are retrieved from cache block A2. Subsequently, cache block A3 is also designated as the target cache block for message retrieval request Q2, and messages with sequence numbers 11-14 are further retrieved from cache block A3. After receiving the return data packet, terminal 10 can display the messages in the return data packet through the client's message display interface, allowing the user to obtain the required messages.

[0049] Terminal 10 can be a smartphone, tablet, laptop, desktop computer, smart TV, wearable device, smartwatch, virtual reality device, vehicle terminal, etc., but is not limited to these.

[0050] Server 20 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The database and cache can be deployed on the same server or on different servers; no specific restrictions are imposed here.

[0051] The solution proposed in this application can be applied to message synchronization scenarios in enterprise instant messaging applications. In enterprise instant messaging applications, after logging in, the enterprise instant messaging client needs to read the latest multiple messages in the enterprise session of its own enterprise from the server. The client's message retrieval request is the message synchronization request. According to the method of this application, the messages with later generation time in the enterprise's message stream can be cached in multiple cache blocks in advance. In this way, after the enterprise instant messaging client logs in later, it can read the messages with later generation time from the cache blocks without accessing the database. This can avoid the problem of excessive database access pressure caused by a large number of message accesses.

[0052] Furthermore, the solution proposed in this application can be applied to group message synchronization scenarios in instant messaging applications. After logging in, the instant messaging client needs to read the latest multiple messages from the group session it is participating in from the server. The client's message retrieval request is the message synchronization request. This message synchronization request can include the session identifier of the session to which the requested synchronized message belongs. The method proposed in this application can be used to pre-cache the later-generated messages in the message stream with more participating users in the session into multiple cache blocks. In this way, after the instant messaging client logs in later, it can read the later-generated messages in the corresponding session from the cache blocks without accessing the database. This can avoid the problem of excessive database access pressure caused by a large number of message accesses.

[0053] The embodiments provided in this application will now be described in detail with reference to the accompanying drawings.

[0054] Please see Figure 2 , Figure 2 A first flowchart of a message retrieval method according to an embodiment of this application is shown. The message retrieval method includes steps S110-S140:

[0055] S110. Obtain the client's message retrieval request; the message retrieval request includes the start sequence number and the number of messages to be retrieved.

[0056] In some implementations, the client's message retrieval request may be sent in response to a specified operation triggered by the client, such as a message refresh operation, a client login operation, or a message retrieval operation.

[0057] In some embodiments, the message retrieved in the message retrieval request can be a session message generated within a conversation, which can be a one-on-one chat or a group conversation. In this case, the client can be an instant messaging application client for individual users or an enterprise instant messaging application client for businesses. Correspondingly, the message retrieval request can be called a session message retrieval request.

[0058] In some embodiments, the message requested in the message retrieval request can also be an operation record, such as document operation records (e.g., document preview records, document editing records, document download records, etc.) for documents in a session, or video operation records (e.g., video preview records, video download records, video forwarding records, etc.) for videos in a session. Correspondingly, the message retrieval request can be called an operation record retrieval request. In some embodiments, the message requested in the message retrieval request can also be an incremental update record of the enterprise's organizational structure. Correspondingly, the message retrieval request can be called an organizational structure update record retrieval request.

[0059] In some implementations, the client can be an enterprise instant messaging client, the message stream can be an enterprise message stream, and the message retrieval request can include the enterprise identifier to which the client belongs, that is, the message retrieval request is used to retrieve messages from the enterprise indicated by the enterprise identifier.

[0060] The start sequence number in a message retrieval request refers to the minimum sequence number of the message requested in the request. In some embodiments, the client may store the maximum sequence number of the message retrieved in the previous message retrieval, and use the sum of the maximum sequence number of the message retrieved in the previous message retrieval and 1 as the start sequence number for the current message retrieval, and initiate a message retrieval request based on this start sequence number.

[0061] The fetch quantity in a message fetch request refers to the number of messages requested to be fetched. In some embodiments, the fetch quantity in a message fetch request can be a default setting, such as 500, 1000, 1500, etc. In some embodiments, the fetch quantity in a message fetch request can be specified by the user on the client side as needed.

[0062] Since message sequence numbers are assigned based on the message's creation time, the earlier the message was created, the smaller its assigned sequence number, and the later the message was created, the larger its assigned sequence number. Therefore, the sequence number of the message to be retrieved in a message retrieval request will not be less than the starting sequence number.

[0063] S120. Based on the reference sequence number and the minimum sequence number of the messages cached in each cache block in the cache, perform a cache block query in the cache to determine the target cache block; the target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, and the minimum sequence number corresponding to the target cache block does not exceed the reference sequence number; a cache block caches the messages in a message block, and the message block is determined by dividing the message stream stored in the database into blocks in ascending order of sequence number; the reference sequence number is initialized to the start sequence number.

[0064] Considering that some data stored in the database may exhibit a read-heavy, write-light characteristic (high read frequency, low write frequency), the high frequency of reads means that retrieving all data from the database for each read would lead to excessive read pressure. For example, in enterprise instant messaging applications, if a company has a large number of employees, each employee logging into the instant messaging client will trigger the retrieval of the latest messages from conversations related to the company. If all these messages were retrieved from the database, it could easily cause database overload.

[0065] Therefore, messages in the message stream with read-heavy and write-light characteristics stored in the database can be cached into multiple cache blocks. Since different clients may need to pull different message sequence numbers from the same message stream, the data reading pressure on the database can be distributed across multiple cache blocks. Moreover, the data reading speed in the cache is usually higher than the data reading speed of the database, which can improve the overall data reading efficiency and reduce the read pressure on the database.

[0066] In some embodiments, message streams that need to be cached in the database can be pre-selected. The selected message streams have the characteristics of being read-heavy and write-light. Then, the selected message streams are divided into blocks and cached in multiple cache blocks.

[0067] In some embodiments, if the database is an enterprise session message database used to store session messages of enterprises in an instant messaging application, the database stores session messages of multiple enterprises. In this database, session messages can be stored on an enterprise-by-enterprise basis; that is, one enterprise corresponds to one enterprise session message stream. This stream can be stored using the enterprise identifier as the key, and each enterprise session message stream includes multiple session messages generated in sequence from the time they were generated within that enterprise's sessions. Considering that the more employees an enterprise has, the more times its session messages need to be retrieved, increasing the read pressure on the database, in some embodiments, the enterprise session message streams that need to be cached can be selected from the database based on the number of employees in the enterprise. For example, enterprise session message streams corresponding to enterprises with more than a first employee threshold can be selected as those requiring caching. Conversely, for enterprise session message streams corresponding to enterprises with fewer than the first employee threshold, the messages do not need to be cached. The first threshold can be set as needed, for example, 500, 800, 1000, etc., and is not specifically limited here.

[0068] Similarly, if the database is an operation record database used to store operation records of enterprise-related electronic documents in instant messaging applications, then the operation record database can store operation records by enterprise. That is, one operation record message stream corresponds to one enterprise, and this operation record message stream can be stored using the enterprise identifier as the key. Each enterprise's corresponding operation record message stream includes multiple operation records generated in chronological order. Furthermore, the operation record message streams to be cached can also be selected from the operation record database based on the number of employees in the enterprise. For example, the operation record message streams corresponding to enterprises with more than a second threshold number of employees can be filtered as the operation record message streams to be cached. The second threshold number can be set according to actual needs, for example, it could be 300, 500, 800, 1000, etc.

[0069] If the database is a record database used to store incremental updates of organizational structures for enterprises in instant messaging applications, it can store these updates on a company-by-company basis. Each company corresponds to one incremental update message stream, which can be stored using the company identifier as the key. Each company's incremental update message stream includes multiple updates generated in chronological order. Furthermore, the database can be used to select message streams for caching based on the number of employees within each company. For example, message streams for companies with more than a third employee threshold can be selected for caching. This third threshold can be set according to actual needs, such as 300, 500, 800, or 1000.

[0070] In some embodiments, in instant messaging applications targeting individual users, message streams can be stored in the database on a session-by-session basis; that is, the message stream identifier of a message stream can be the session identifier of the corresponding session. Message streams corresponding to sessions with more than a fourth threshold of participating users can be designated as message streams to be cached based on the number of participating users in the corresponding session.

[0071] For message streams identified in the database as needing caching, the process can involve either chunking and caching all messages in the stream or chunking and caching only a portion of them. Considering that messages generated earlier are read less frequently, while messages generated later are read more frequently, it's advisable to chunk and cache later-generated messages, while earlier-generated messages don't need to be cached. For example, regarding... Figure 1B The message flow shown can cache messages in message blocks A2 and A3, but does not need to cache messages in message block A1.

[0072] In some embodiments, considering that messages in the message stream are assigned sequence numbers according to their generation time, and that the earlier the generation time, the smaller the sequence number, and the later the generation time, the larger the sequence number, the K messages with the largest sequence numbers in the message stream that need to be cached can be selected as the messages that need to be cached in blocks, where K is an integer greater than 1, and K can be set as needed, for example, K is 1000, 1500, 2000, etc.

[0073] In the above embodiments, message streams that are read frequently from the database and messages that are read frequently from the message streams are cached in the cache, instead of caching all message streams in the database. This reduces the cache usage and improves the cache utilization, thus balancing the reduction of data reading pressure on the database and the utilization of the cache.

[0074] A cache block is the smallest unit of cache management; each cache block has a corresponding cache capacity, and the capacity of the messages cached in a cache block cannot exceed the cache capacity of the cache block. A cache can be divided into multiple cache blocks.

[0075] Since message blocks are determined by dividing the message stream stored in the database into blocks in ascending order of sequence number, for any two message blocks (let's say message block A1 and message block A2), the sequence numbers of the messages in message block A1 are either all less than or all greater than the sequence numbers of the messages in message block A2. There will not be a situation where some messages in message block A1 have sequence numbers greater than some messages in message block A2, while other messages in message block A1 have sequence numbers less than some messages in message block A2. In other words, when sorted by sequence number in ascending order, in two adjacent message blocks in the message stream, the largest sequence number of the messages in the preceding message block is less than the smallest sequence number of the messages in the following message block.

[0076] In some implementations, the maximum number of messages that need to be cached in each cache block can be preset as the first quantity. The messages that need to be cached in the message stream can be divided into multiple message blocks based on the first quantity. Specifically, messages that are selected sequentially up to the first quantity in ascending order of their sequence numbers are selected to obtain a message block.

[0077] In other implementations, the message stream can be divided into multiple message blocks by combining a first quantity and a block start number set for each cache block; wherein the sequence number of the messages cached in a cache block is not lower than the block start number set for that cache block. That is, the messages cached in a cache block are no more than a first quantity of messages whose sequence numbers start from the block start number.

[0078] For example, the first quantity can be set to 1000, and the starting sequence number of each Nth cache block can be k = 1000(N-1). That is, the sequence number interval between the starting sequence numbers of two adjacent cache blocks is the same. Here, N represents the sequence number of the cache block. For the first cache block, its starting sequence number is 0, that is, the first message block contains 1000 messages selected from the smallest to the largest sequence number 0. For the second cache block, its starting sequence number is 1000, and it contains 1000 messages selected from the smallest to the largest sequence number 1000. And so on, to obtain multiple message blocks. In this case, since the message sequence numbers are not necessarily consecutive, different cache blocks can contain the same messages. For example, the first message block contains messages with sequence numbers 0-1030 (a total of 1000 messages), and the second message block contains messages with sequence numbers 1020-2130 (a total of 1000 messages). Obviously, the first message block and the second message block contain the same messages.

[0079] In some embodiments, the message stream can be divided into blocks based on a block start number set for each cache block. For the i-th cache block, messages in the message stream whose sequence number is not less than the block start number corresponding to the i-th cache block and less than the block start number corresponding to the (i+1)-th cache block can be grouped into one message block, and this message block can be cached in the i-th cache block, where i is a positive integer. The sequence number interval between the block start numbers of two adjacent cache blocks can be the same or different, depending on actual needs. It is worth noting that since the sequence numbers of adjacent messages in the message stream are not necessarily consecutive, there may not be any messages in each cache block whose sequence number matches the block start number corresponding to that cache block.

[0080] The minimum sequence number of a message cached in a cache block can refer to the starting sequence number of the block set above for the cache block. That is, the minimum sequence number corresponding to a cache block refers to the minimum sequence number of the message that the cache block is allowed to cache, or it can be the minimum sequence number of the actual cached message in the cache block.

[0081] In some embodiments, each cache block may also maintain basic information about the cached message, such as the message stream identifier of the message stream from which the message originates and the minimum sequence number of the message cached in the cache block.

[0082] In some embodiments, cache blocks can also cache messages in the form of key-value pairs. The key of a cache block can be a character sequence formed by concatenating the message stream identifier of the message stream from which the cached message originates, and the smallest sequence number of the cached message. The value of a cache block can be a list of cached messages and the message content of each message in the list. The key of a cache block can serve as basic information about the cached message. The message stream identifier can be the enterprise identifier of the enterprise to which the message stream belongs, but it is not limited to this. For example, the key of a cache block could be: `corpid_seqfloor`, where `corpid` is the enterprise identifier, i.e., the message stream identifier of the message stream from which the cached message originates, and `seqfloor` is the smallest sequence number of the cached message, such as the block start sequence number mentioned above.

[0083] After initializing the reference sequence number to the start sequence number, the determined target cache block is the cache block with the smallest sequence number interval between the corresponding minimum sequence number and the reference sequence number among the cache blocks whose corresponding minimum sequence number does not exceed the reference sequence number. This indicates that the target cache block will contain messages with a sequence number not less than the start sequence number, which is the message requested by the message retrieval request.

[0084] In some implementations, the client is an enterprise instant messaging client, the message stream is an enterprise message stream, and the message retrieval request includes the enterprise identifier to which the client belongs; step S120 includes:

[0085] Based on the reference sequence number and the minimum sequence number of the message cached in each cache block associated with the enterprise identifier, a cache block query is performed in the cache associated with the enterprise identifier to determine the target cache block.

[0086] Among them, each cache block in the cache associated with the enterprise identifier caches messages under the enterprise indicated by that enterprise identifier.

[0087] For example, if the key of a cache block is the message stream identifier of the message stream from which the cached message originates, and the character sequence formed by concatenating the key with the smallest sequence number of the cached message, the target cache block can be determined by querying cache blocks whose message stream identifier in the key is the enterprise identifier of the client's enterprise.

[0088] As described above, in some embodiments, only some messages from a message stream may be cached in the cache block in the database. Furthermore, some messages from a partial message stream may be cached in the cache block. The target message stream identifier in the message retrieval request and the start sequence number in the message retrieval request can be used to determine whether the message requested by the message retrieval request is in the cache. If it is in the cache, it is processed according to step S120 and subsequent steps. If it is not in the cache, the message requested by the message retrieval request is read from the database.

[0089] For example, if, based on the basic information maintained by each cache block (such as the key of each cache block), it is determined that at least one first cache block exists in the cache, where the message flow identifier in the basic information of the first cache block is the same as the message flow identifier in the message retrieval request, and the minimum sequence number in the basic information is not less than the start sequence number in the message retrieval request, it can be determined that the message requested by the message retrieval request is located in the cache; conversely, if, based on the basic information maintained by each cache block, it is determined that no first cache block exists in the cache, it is determined that the message requested by the message retrieval request has not been cached in the cache block.

[0090] S130. Read the target number of messages from the target cache block whose sequence number is not less than the reference sequence number and whose sequence number is the smallest, and add the read messages to the return data packet for the message retrieval request; the target number does not exceed the retrieval number.

[0091] The target quantity is the minimum of the number of messages pulled and the number of messages in the target cache block whose sequence number is not less than the reference sequence number. For example, if the number of messages pulled is 500, and the number of messages in the target cache block whose sequence number is not less than the reference sequence number is 200, then the target quantity is 200. If the number of messages in the target cache block whose sequence number is not less than the reference sequence number is 600, then the target quantity is 500.

[0092] Obviously, when the target number is the number of messages to be pulled, it means that the messages cached in the target cache block can satisfy the message pull request; when the target number is less than the number of messages to be pulled, it means that the messages requested by the message pull request may exist in other cache blocks besides the currently determined target cache block.

[0093] S140. If the number of messages in the returned data packet reaches the required number of messages to be retrieved, send a returned data packet to the client.

[0094] If the number of messages in the returned data packet reaches the required number to be retrieved, it means that all the messages requested in the message retrieval request have been read, and therefore, a data packet can be returned to the client.

[0095] The method provided in this application divides the message stream stored in the database into blocks according to the sequence number in ascending order, and then caches these blocks into multiple cache blocks. Upon receiving a message retrieval request, the reference sequence number is initialized to the start sequence number in the message retrieval request. Then, based on the reference sequence number and the minimum sequence number of the messages cached in each cache block, a target cache block with the smallest sequence number interval between the minimum sequence number and the reference sequence number is determined. A target number of messages with sequence numbers not less than the reference sequence number and the smallest sequence number are read from the target cache block, and these read messages are added to the return data packet for the message retrieval request. If the number of messages in the return data packet reaches the retrieval target, a return message is sent to the client. This allows messages to be read from a buffer block and returned to the client without needing to read messages from the database. When faced with multiple message retrieval requests simultaneously, each request will determine its corresponding target buffer block based on its different start sequence number and read messages from the corresponding target buffer block. This means that multiple message retrieval requests can read the required messages from different target buffer blocks, which means that the pressure of reading messages from the database can be distributed across multiple buffer blocks. Moreover, reading from the cache is faster than reading from the database, which can improve the message retrieval rate. Therefore, it can effectively reduce the problem of high database access pressure caused by needing to read messages from the database multiple times and avoid database overload.

[0096] In some implementations, please refer to Figure 3 , Figure 3 A second flowchart of a message retrieval method according to another embodiment of this application is shown. Each cache block also stores a first field. The value of the first field in a cache block is used to indicate whether there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block. After step S130, the message retrieval method further includes step S150:

[0097] S150. If the number of messages in the returned data packet does not reach the number of messages to be retrieved, and the condition for continuing to retrieve is met based on the value of the first field in the target cache block, the reference sequence number is updated to the maximum sequence number of the messages cached in the target cache block, and the target number is updated to the difference between the number of messages to be retrieved and the number of messages in the returned data packet.

[0098] After step S150, return to step S120.

[0099] The number of messages in the returned data packet is the number of messages that have been read. After fetching messages from one target cache block, the maximum number of messages that can be requested from another cache block is the difference between the number of messages fetched and the number of messages in the returned data packet.

[0100] The conditions for continuing to fetch include a first condition, which means that the value of the first field in the target cache block is the first value; when the value of the first field in a cache block is the first value, it means that there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block.

[0101] In some embodiments, the basic information maintained by the cache block for the cached messages may also include the maximum sequence number of the messages cached by the cache block. For example, each cache block may store a second field, the value of which is set to the maximum sequence number of the messages cached by the cache block, that is, the maximum sequence number of the messages actually cached in the cache block.

[0102] If there are messages in the message stream with sequence numbers greater than the maximum sequence number in the target cache block, it indicates that there are other cache blocks that cache other messages in the message stream whose generation time is later than the maximum sequence number in the target cache block. Moreover, the number of messages in the current returned data packet has not reached the number to be fetched. Therefore, it indicates that messages still need to be read from other cache blocks.

[0103] In some implementations, the value of the first field of the cache block can be returned by the database when the cache block reads the message to be cached from the database; for example, the sequence number of the message stream stored in the database is 0-3000, and the sequence number of the message read by the cache block from the database is 1000-2000. In this case, the database can return the first field with the first value to the cache block, and the cache block will use the received first value as the value of the first field.

[0104] In some implementations, if the number of messages in the returned data packet does not reach the required number to be retrieved, and the value of the first field in the target cache block determines that the conditions for continuing to retrieve are not met, it means that there are no messages in the message stream that satisfy the message retrieval request. Therefore, a returned data packet can be sent to the client.

[0105] For example, if the value of the first field in a cache block is the second value, it means that there is no message in the message stream with a sequence number greater than the maximum sequence number in the cache block. If the value of the first field in the target cache block is the second value, it means that the current target cache block caches the latest message in the corresponding message stream. In this case, it can be determined that the condition for continuing to fetch is not met.

[0106] In some implementations, after step S120, the message retrieval method may further include the following steps:

[0107] The cumulative cache lookup count for message fetch requests will be incremented by 1.

[0108] Based on this, the conditions for continuing to fetch in step S150 may also include a second condition, which means that the number of cache queries for the message fetch request is less than the number threshold.

[0109] When the first condition is met based on the value of the first field in the target cache block, and the second condition is met based on the number of cache queries for the message fetch request, the condition for continuing to fetch is determined to be met.

[0110] In the above implementation, a cache lookup count for message fetching requests is introduced. If the second condition is not met, the condition for continuing to fetch is considered not met. That is, if the cache lookup count for a message fetching request is not less than the count threshold, fetching will not continue. This can avoid multiple cache block lookups for the same message fetching request, which would cause the message reading time of a single message fetching request to be too long and result in a poor user experience.

[0111] In some implementations, after step S130, the message retrieval method may further include:

[0112] If the number of messages in the returned data packet does not reach the required number to be retrieved, and it is determined that neither the first nor the second condition is met, a return data packet is sent to the client.

[0113] Understandably, if the first condition is not met, it means that there are no messages in other cache blocks whose generation time is later than the message with the largest sequence number in the target cache block. In this case, it is impossible to obtain a message with a sequence number larger than the largest sequence number in the target cache block. If the second condition is not met, it means that multiple fetches have been performed for the message fetch request, which has taken a long time. If fetching continues, the message fetching time may be too long, which will reduce the user experience. Therefore, if it is determined that either the first condition or the second condition is not met, a return data packet can still be sent to the client even if the number of messages in the return data packet does not reach the fetching quantity.

[0114] Please see Figure 4 , Figure 4 A third flowchart of a message retrieval method according to another embodiment of this application is shown. The returned data packet also includes a first indicator field and a second indicator field. Before step S140, the message retrieval method includes steps S210-S230:

[0115] S210. If the value of the first field in the last target cache block determined by the message retrieval request is the first value, or the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet, the first value is assigned to the first indicator field; wherein, when the value of the first field in the last target cache block is the first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block.

[0116] The first indication field in the returned data packet is used to indicate whether message retrieval needs to be performed again, and the second indication field is used to determine the start sequence number in the message retrieval request.

[0117] If the value of the first field in the last target cache block determined by the message retrieval request is the first value, it indicates that there is a message in the message stream with a sequence number greater than the largest sequence number in the last target cache block. This means that other cache blocks also cache the message with the largest sequence number of the return data packet that was generated later than the current message in the message stream. Therefore, the first value can be assigned to the first indicator field to indicate that messages generated later need to be retrieved again.

[0118] Similarly, when reading messages cached in the last target cache block, messages with sequence numbers not less than the reference sequence number are read in ascending order. Therefore, if the maximum sequence number of a message cached in the last target cache block is greater than the maximum message sequence number in the return data packet, it means that the last target cache block also caches the message with the largest sequence number in the return data packet whose generation time is later than the current one. Therefore, the first value can be assigned to the first indicator field to indicate that messages with later generation times need to be retrieved again.

[0119] S220. If the value of the first field in the last target cache block is the second value, and the maximum sequence number of the message cached in the last target cache block is equal to the maximum message sequence number in the returned data packet, assign the second value to the first indicator field; wherein, when the value of the first field in the last target cache block is the second value, it indicates that there is no message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block.

[0120] When reading messages cached in the last target cache block, messages with sequence numbers not less than the reference sequence number are read in ascending order. Therefore, the maximum sequence number of the messages cached in the last target cache block is equal to the maximum sequence number of the returned data packet, which means that there is no message in the last target cache block whose generation time is later than the current maximum sequence number of the returned data packet. At the same time, the value of the first field in the last target cache block is the second value, which means that there is no message in the corresponding message stream with a sequence number greater than the maximum sequence number in the last target cache block. Therefore, the second value is assigned to the first indicator field to indicate that message retrieval is not required again.

[0121] S230. Based on the value of the first field in the last target cache block, assign one of the maximum sequence number of the cached messages in the last target cache block and the maximum message sequence number in the returned data packet to the second indicator field; wherein, the value of the second indicator field is used to determine the start sequence number of the next request to fetch messages.

[0122] Specifically, when the value of the second indicator field is k, the starting sequence number of the next request to fetch messages is k+1, where k is a positive integer.

[0123] In some implementations, step S230 may include step one and step two:

[0124] Step 1: If the value of the first field in the last target cache block is the second value, and the maximum sequence number of the cached message in the last target cache block is equal to the maximum message sequence number in the returned data packet, assign the maximum sequence number of the cached message in the last target cache block to the second indicator field.

[0125] The value of the first field in the last target cache block is the second value, and the maximum sequence number of the message cached in the last target cache block is equal to the maximum message sequence number in the return data packet. This means that there is no message in the last target cache block that was generated later than the current return data packet with the largest sequence number, and there is no message in the corresponding message stream with a sequence number greater than the current return data packet with the largest sequence number. Therefore, the maximum sequence number of the message cached in the last target cache block (which is also equal to the maximum message sequence number in the return data packet at this time) is assigned to the second indicator field.

[0126] Step 2: If the value of the first field in the last target cache block is the first value, or if the maximum sequence number of the cached message in the last target cache block is greater than the maximum sequence number of the message in the return data packet, assign the minimum value between the maximum sequence number of the cached message in the last target cache block and the maximum sequence number of the message in the return data packet to the second indicator field.

[0127] The value of the first field in the last target cache block is the first value, indicating that there is still a message in the corresponding message stream with the largest sequence number of the return data packet generated later than the current one. If the largest sequence number of the message cached in the last target cache block is greater than the largest sequence number of the return data packet, it indicates that there is a message in the last target cache block with the largest sequence number of the return data packet generated later than the current one. Regardless of whether there is a message in the message stream with the largest sequence number of the return data packet generated later than the current one, or a message in the last target cache block with the largest sequence number of the return data packet generated later than the current one, it indicates that the message with the largest sequence number of the return data packet generated later than the current one can continue to be retrieved. Therefore, the minimum value between the largest sequence number of the message cached in the last target cache block and the largest sequence number of the return data packet is assigned to the second indicator field.

[0128] Specifically, if the maximum sequence number of the message cached in the last target cache block is greater than the maximum sequence number of the message in the return data packet, the maximum sequence number of the message in the return data packet is assigned to the second indicator field; otherwise, the maximum sequence number of the message cached in the last target cache block is assigned to the second indicator field.

[0129] In some implementations, after step S140, the message retrieval method further includes:

[0130] The client receives a second message retrieval request. The start sequence number in the second message retrieval request is equal to the sum of the value of the second indicator field in the returned data packet and 1. The second message retrieval request is sent by the client after detecting that the value of the first indicator field in the returned data packet is the first value.

[0131] As described in the foregoing embodiments, the value of the first indicator field in the returned data packet is a first value, which means that the message with the largest sequence number of the returned data packet generated later than the current one can continue to be retrieved. Therefore, if the value of the first indicator field in the returned data packet is detected to be a first value, a second message retrieval request can be sent to obtain the latest message. The number of messages retrieved in the second message retrieval request can be the same as the number of messages retrieved in step S110.

[0132] In some implementations, after the client detects that the value of the first indicator field in the returned data packet is the first value, it may display a prompt message to prompt the user to continue fetching information. Then, in response to the user's triggering operation, it may issue another message fetching request.

[0133] In some implementations, please refer to Figure 5 , Figure 5 The fourth flowchart of the message retrieval method provided in this application embodiment is shown. After step S130, the message retrieval method further includes steps S310-S320:

[0134] S310. Obtain the valid status information of the target cache block.

[0135] It is understandable that the messages sent by the client are stored in the database, while the messages in the cache block are retrieved from the database. Therefore, by setting the expiration time of the cache block and retrieving the message from the database after the cached message expires, the consistency between the message cached in the cache block and the message stored in the database can be ensured.

[0136] You can set an expiration period for each cache block. If a message in the cache block expires after the specified time, it can be determined that the message in that cache block has expired. The duration of the expiration period can be set according to actual needs, such as 1 day, 2 days, etc. There is no specific limit here.

[0137] S320. If the valid status information indicates that the target cache block has expired, the database sequentially reads a reference number of messages with a sequence number not less than the minimum sequence number corresponding to the target cache block from the message stream according to the minimum sequence number corresponding to the target cache block, and caches the read messages into the target cache block; the reference number is the maximum number of messages that the target cache block is allowed to cache.

[0138] Through the above implementation, when the target cache block expires, the message is reread from the database and cached in the corresponding cache block. This ensures that subsequent messages read from the cache block are still valid. It also enables the updating of messages cached in the target cache block, ensuring consistency between the messages in the target cache block and those stored in the database, thereby guaranteeing the timeliness of messages in the returned data packet.

[0139] As time progresses, the message stream may accumulate messages with later creation times. In such cases, messages previously cached in the cache block may be older than the current creation time. Therefore, in this situation, later-created messages from the message stream can be cached in the cache block to replace earlier-created messages in the cache block. It's worth noting that when a cached message in a cache block is replaced, the corresponding key for the cache block, or the basic information mentioned above, needs to be updated.

[0140] Please see Figure 6 , Figure 6 A schematic diagram of message retrieval according to another embodiment of this application is provided.

[0141] In this message stream, the message sequence number monotonically increases from the earliest to the latest message generation time. The later the message is generated, the larger its sequence number. However, the message sequence numbers are not necessarily consecutive. For example, the message stream includes messages with sequence numbers ranging from 0 to 5331. Specifically, there are 995 messages between sequence numbers 0 and 1000, 653 messages between sequence numbers 1000 and 2000, 773 messages between sequence numbers 2000 and 3000, 0 messages between sequence numbers 3000 and 4000, 759 messages between sequence numbers 4000 and 5000, and 63 messages between sequence numbers 5000 and 5331.

[0142] Message blocks are obtained by dividing the message stream according to a preset number and a starting sequence number. For example, in this application scenario, the preset number of each message block is 1000, and the starting sequence number of the block is an integer multiple of 1000.

[0143] Each cache block can be stored as a key-value pair structure. Each cache block can use a combination of the block start sequence number and ID (i.e., the enterprise identifier) ​​as the key, and the cached message and the value of the first field as the value of the cache block, thus obtaining... Figure 6 The five cache blocks shown.

[0144] Among the three cache blocks ID-0, ID-1000, and ID-2000, the maximum sequence numbers of the cached messages are 1055, 2332, and 4456, respectively. Clearly, the maximum sequence number of the messages cached in these three cache blocks is less than the maximum sequence number of messages in the message stream, which is 5331. Therefore, for the three cache blocks ID-0, ID-1000, and ID-2000, the value of the first field is always the first value. Figure 6 In this context, true represents the first value.

[0145] Similarly, for the three cache blocks ID-3000 and ID-4000, the maximum sequence number of the cached messages is 5331, which is equal to the maximum sequence number of the messages in the message stream, also 5331. Therefore, for the three cache blocks ID-3000 and ID-4000, the value of the first field is the second value. Figure 6 In this context, false represents the second value.

[0146] For a client's message retrieval request, assuming the client's message retrieval request contains a start sequence number of 2556, a retrieval quantity of 1000, a threshold of 2, and an initial query count of 0, the processing procedure is as follows:

[0147] Upon receiving a message retrieval request from the client, the reference sequence number is initialized to the starting sequence number, i.e., 2556. Among multiple cache blocks, the corresponding minimum sequence number does not exceed 2556, and the cache block with the smallest sequence number interval between the corresponding minimum sequence number and 2556 is the cache block indicated by ID-2000. That is, the target cache block is the cache block indicated by ID-2000.

[0148] The messages with sequence numbers not less than 2556 in the target cache block (i.e., the cache block indicated by ID-2000) are filled into the return data packet in ascending order, and the cache query count is updated from 0 to 1.

[0149] After reading the target cache block, it was found that the returned data packet contained only 800 messages (i.e., there were only 800 messages with a sequence number of not less than 2556 in the cache block indicated by ID-2000), which was less than the pull quantity of 1000. The first field of the cache block indicated by ID-2000 was the first value (true), and the cache query count was 1, which was still less than the count threshold of 2. The conditions for continuing to pull were met. Therefore, the reference sequence number was updated to the maximum sequence number of the cached messages in the target cache block, which was 4456. The target quantity was updated to 200, which was the difference between the pull quantity of 1000 and the number of messages in the returned data packet of 800.

[0150] Based on reference number 4456, the target cache block can be redefined as the cache block indicated by ID-4000, which has 823 messages. Therefore, the minimum 200 messages with a sequence number not less than 4456 are read and filled into the return data packet, and the number of messages in the return data packet can reach 1000, which meets the pull requirement.

[0151] Assuming the maximum sequence number in the returned data packet is 4680, which is less than the maximum sequence number of the last target cache block ID-4000 (5331), it means that there are still messages in the last target cache block ID-4000 that satisfy the message retrieval request but have not been filled into the returned data packet. Therefore, the first value true is assigned to the first indicator field of the returned data packet, and the maximum sequence number 4680 in the returned data packet is assigned to the second indicator field. That is, the returned data packet includes: 1000 messages, the first indicator field is true, and the second indicator field is 4680.

[0152] After the client receives the returned data packet, since the first indicator field in the returned data packet is true, it means that message retrieval can continue. Therefore, the client sends a message retrieval request again based on the returned data packet. The start sequence number of the message retrieval request is 4681 (4680+1), and the number of messages to be retrieved is 1000.

[0153] The processing procedure for subsequent message retrieval requests from the client is as follows:

[0154] Based on the start sequence number 4681 of the message retrieval request, the target cache block can be determined to be ID-4000. Messages with sequence numbers not less than 4681 in the target cache block (i.e., the cache block indicated by ID-4000) are filled into the return data packet in ascending order. At the same time, the cache query count is updated from 0 to 1.

[0155] Since the target cache block ID-4000 contains 823 messages, the number of messages in the returned data packet will inevitably be less than the number of messages retrieved. Assuming that 600 messages are retrieved in the returned data packet (i.e., there are only 600 messages with a sequence number of not less than 4681 in the cache block indicated by ID-4000), although the number of messages in the returned data packet is less than the number of messages retrieved, the condition for continuing to retrieve messages is not met because the first indication field of the target cache block ID-4000 is false. Therefore, a returned data packet is sent to the client.

[0156] Clearly, the maximum sequence number in the returned data packet is 5331, which is equal to the maximum sequence number in the target cache block ID-4000. Furthermore, the value of the first field of the target cache block ID-4000 is the second value. Therefore, it can be determined that the first indicator field of the returned data packet is the second value false, and the second indicator field is the maximum sequence number 5331 of the message cached in the last target cache block ID-4000. That is, the returned data packet for the message retrieval request includes: 1000 messages, the first indicator field is false, and the second indicator field is 5331.

[0157] After receiving the returned data packet, the client finds that the first indicator field of the returned data packet is false and stops sending message retrieval requests.

[0158] It is worth mentioning that before reading messages from the target cache block, if it is detected that the target cache block has expired, the latest message data is retrieved from the database based on the minimum sequence number of the target cache block and a preset number. Taking the expiration of target cache block ID-2000 as an example, it is necessary to use the minimum sequence number of the target cache block ID-2000, 2000, as the starting sequence number, and read the 1000 messages with the smallest sequence number starting from sequence number 2000 from the database, thereby updating the target cache block ID-2000.

[0159] Please see Figure 7 , Figure 7 A schematic diagram of a message retrieval device according to an embodiment of this application is provided. The message retrieval device 600 includes:

[0160] The acquisition module 610 is used to acquire the message retrieval request from the client; the message retrieval request includes the start sequence number and the number of messages to be retrieved.

[0161] The query module 620 is used to query the cache block in the cache based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache, and determine the target cache block; the target cache block is the cache block with the smallest sequence number interval between the corresponding minimum sequence number and the reference sequence number, and the minimum sequence number of the target cache block does not exceed the reference sequence number; a cache block caches the message in a message block, and the message block is determined by dividing the message stream stored in the database into blocks in ascending order of sequence number; the reference sequence number is initialized to the start sequence number.

[0162] The reading module 630 is used to read a target number of messages from the target cache block whose sequence number is not less than the reference sequence number and whose sequence number is the smallest, and to add the read messages to the return data packet for the message retrieval request; the target number does not exceed the retrieval number.

[0163] The response module 640 is used to send a return data packet to the client if the number of messages in the returned data packet reaches the required number to be retrieved.

[0164] In some implementations, each cache block also stores a first field; the value of the first field in a cache block is used to indicate whether there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block; the message retrieval device 600 further includes a judgment module, used to update the reference sequence number to the maximum sequence number of the cached message in the target cache block and update the target quantity to the difference between the retrieval quantity and the number of messages in the returned data packet if the number of messages in the returned data packet has not reached the retrieval quantity and the retrieval condition is satisfied based on the value of the first field in the target cache block; a loop execution module is used to return to the step of performing a cache block query in the cache based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache to determine the target cache block; wherein, the retrieval condition includes a first condition, which means that the value of the first field in the target cache block is a first value; wherein, when the value of the first field in a cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block.

[0165] In some implementations, the message fetching device 600 further includes an update module for incrementing the cumulative number of cache queries for the message fetching request by 1; the continued fetching condition also includes a second condition, which is that the number of cache queries for the message fetching request is less than a threshold; the judgment module is specifically used to determine that the continued fetching condition is met when the first condition is met based on the value of the first field in the target cache block and the second condition is met based on the number of cache queries for the message fetching request.

[0166] In some implementations, the response module 640 is further configured to send a return data packet to the client if the number of messages in the returned data packet does not reach the number of fetches and it is determined that neither the first condition nor the second condition is met.

[0167] In some implementations, the returned data packet further includes a first indicator field and a second indicator field; the message retrieval device 600 further includes a first assignment module, configured to assign the first value to the first indicator field if the value of the first field in the last target cache block determined by the query for the message retrieval request is a first value, or if the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet; wherein, when the value of the first field in the last target cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block; and, if the value of the first field in the last target cache block is a first value, the first indicator field is a second indicator field. The second value is assigned to the first indicator field, where the maximum sequence number of the message cached in the last target cache block is equal to the maximum sequence number of the message in the returned data packet. When the value of the first field in the last target cache block is the second value, it indicates that there is no message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block. The second assignment module is used to assign one of the maximum sequence number of the message cached in the last target cache block and the maximum sequence number of the message in the returned data packet to the second indicator field based on the value of the first field in the last target cache block. The value of the second indicator field is used to determine the starting sequence number for the next message retrieval request.

[0168] In some implementations, the second assignment module is specifically used to assign the maximum sequence number of the cached message in the last target cache block to the second indicator field if the value of the first field in the last target cache block is a first value and the maximum sequence number of the cached message in the last target cache block is equal to the maximum message sequence number in the return data packet; and if the value of the first field in the last target cache block is a second value, or the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the return data packet, the minimum value between the maximum sequence number of the cached message in the last target cache block and the maximum message sequence number in the return data packet is assigned to the second indicator field.

[0169] In some implementations, the acquisition module 610 is also used to receive a re-message retrieval request sent by the client, wherein the start sequence number in the re-message retrieval request is equal to the sum of the value of the second indicator field in the returned data packet and 1; the re-message retrieval request is sent by the client after detecting that the value of the first indicator field in the returned data packet is the first value.

[0170] In some implementations, the message retrieval device 600 further includes a cache status judgment module for obtaining valid status information of the target cache block; and a cache update module for requesting the database to sequentially read a reference number of messages with a sequence number not less than the minimum sequence number corresponding to the target cache block from the message stream if the valid status information indicates that the target cache block has expired, based on the minimum sequence number corresponding to the target cache block, and caching the read messages into the target cache block; the reference number is the maximum number of messages that the target cache block is allowed to cache.

[0171] In some implementations, the message retrieval request further includes a target message stream identifier of the target message stream to which the requested message belongs; the message retrieval device further includes a cache determination module, used to determine whether the message requested by the message retrieval request is located in the cache based on the message stream identifier and start sequence number in the message retrieval request, and the message stream identifier and corresponding minimum sequence number of the message cached in each cache block in the cache; the query module is further used to determine the target cache block by performing a cache block query in the cache based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache if it is determined that the message requested by the message retrieval request is located in the cache.

[0172] In some implementations, the client is an enterprise instant messaging client, the message stream is an enterprise message stream, and the message retrieval request includes the enterprise identifier to which the client belongs; the query module 620 is also used to perform a cache block query in the cache associated with the enterprise identifier based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache associated with the enterprise identifier, and to determine the target cache block.

[0173] Figure 8 A schematic diagram of a computer system suitable for implementing an electronic device according to embodiments of this application is shown. The electronic device can be the terminal described above, used to implement the message retrieval method provided in this application. It should be noted that... Figure 8 The computer system 1300 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0174] like Figure 8As shown, the computer system 1300 includes a Central Processing Unit (CPU) 1301, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 1302 or programs loaded from storage portion 1308 into Random Access Memory (RAM) 1303. The RAM 1303 also stores various programs and data required for system operation. The CPU 1301, ROM 1302, and RAM 1303 are interconnected via a bus 1304. An Input / Output (I / O) interface 1305 is also connected to the bus 1304.

[0175] The following components are connected to I / O interface 1305: an input section 1306 including a keyboard, mouse, microphone, etc.; an output section 1307 including a cathode ray tube (CRT), liquid crystal display (LCD), and speakers, etc.; a storage section 1308 including a hard disk, etc.; and a communication section 1309 including a network interface card such as a LAN (Local Area Network) card and a modem, etc. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to I / O interface 1305 as needed. Removable media 1311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1310 as needed so that computer instructions read from them can be loaded into storage section 1308 as needed.

[0176] In particular, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising computer instructions. When these computer instructions are executed by the central processing unit (CPU) 1301, various functions defined in the system of this application are performed.

[0177] This application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the methods described in any of the above method embodiments.

[0178] It should be noted that the computer-readable storage medium shown in the embodiments of this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such transmitted data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0179] In the embodiments of this application, the terms "module" or "unit" refer to computer instructions or a portion of computer instructions that have a predetermined function and work together with other related parts to achieve a predetermined goal. These instructions can be implemented, wholly or partially, using software, hardware (e.g., processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that functions as a whole.

[0180] The above are merely preferred embodiments of this application and are not intended to limit this application in any way. Although this application has disclosed preferred embodiments as above, it is not intended to limit this application. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the technical solution of this application. Any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of this application without departing from the scope of the technical solution of this application shall still fall within the scope of the technical solution of this application.

Claims

1. A message retrieval method, characterized in that, include: Get the client's message fetch request; The message retrieval request includes the start sequence number of the requested messages and the number of messages to be retrieved; Based on the reference sequence number and the minimum sequence number of the messages cached in each cache block in the cache, a cache block query is performed in the cache to determine the target cache block; the target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, and the minimum sequence number does not exceed the reference sequence number; a cache block caches the messages in a message block, and the message block is determined by dividing the message stream stored in the database into blocks in ascending order of sequence number; the reference sequence number is initialized to the start sequence number; Read a target number of messages from the target cache block whose sequence number is not less than the reference sequence number and whose sequence number is the smallest, and add the read messages to the return data packet for the message retrieval request; The target quantity does not exceed the number of fetches; If the number of messages in the returned data packet reaches the required number of fetches, the returned data packet is sent to the client.

2. The method according to claim 1, characterized in that, Each of the cache blocks also stores a first field; the value of the first field in a cache block is used to indicate whether there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block; After reading a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and adding the read messages to the return data packet for the message retrieval request, the method further includes: If the number of messages in the returned data packet does not reach the fetch quantity, and the condition for continuing to fetch is determined based on the value of the first field in the target cache block, the reference sequence number is updated to the maximum sequence number of the cached messages in the target cache block, and the target quantity is updated to the difference between the fetch quantity and the number of messages in the returned data packet. Return to the step of performing the query in the cache based on the reference sequence number and the smallest sequence number of the messages cached in each cache block in the cache to determine the target cache block; The condition for continuing to fetch includes a first condition, which means that the value of the first field in the target cache block is a first value; wherein, when the value of the first field in a cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number in the cache block.

3. The method according to claim 2, characterized in that, After determining the target cache block by performing a cache block lookup in the cache based on the reference sequence number and the smallest sequence number of messages cached in each cache block in the cache, the method further includes: The cumulative number of cache queries for the aforementioned message retrieval request will be incremented by 1. The condition for continuing to fetch also includes a second condition, which means that the number of cache queries for the message fetch request is less than a threshold. When the first condition is satisfied based on the value of the first field in the target cache block, and the second condition is satisfied based on the number of cache queries for the message retrieval request, the condition for continuing retrieval is determined to be satisfied.

4. The method according to claim 3, characterized in that, After reading a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and adding the read messages to the return data packet for the message retrieval request, the method further includes: If the number of messages in the returned data packet does not reach the number of messages to be retrieved, and it is determined that neither the first condition nor the second condition is met, the returned data packet is sent to the client.

5. The method according to any one of claims 2 to 4, characterized in that, The returned data packet also includes a first indication field and a second indication field; Before sending the return data packet to the client, the method further includes: If the value of the first field in the last target cache block determined by the message retrieval request is a first value, or if the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet, the first value is assigned to the first indicator field; wherein, when the value of the first field in the last target cache block is a first value, it indicates that there is a message in the message stream with a sequence number greater than the maximum sequence number of the last target cache block; If the value of the first field in the last target cache block is the second value, and the maximum sequence number of the message cached in the last target cache block is equal to the maximum message sequence number in the returned data packet, the second value is assigned to the first indicator field; wherein, when the value of the first field in the last target cache block is the second value, it indicates that there is no message in the message stream with a sequence number greater than the maximum sequence number in the last target cache block; Based on the value of the first field in the last target cache block, one of the maximum sequence number of the messages cached in the last target cache block and the maximum message sequence number in the returned data packet is assigned to the second indicator field; wherein, the value of the second indicator field is used to determine the start sequence number of the next request to fetch messages.

6. The method according to claim 5, characterized in that, The step of assigning one of the maximum sequence number of the messages cached in the last target cache block and the maximum message sequence number in the returned data packet to the second indication field based on the value of the first field in the last target cache block includes: If the value of the first field in the last target cache block is the second value, and the maximum sequence number of the cached message in the last target cache block is equal to the maximum message sequence number in the returned data packet, then the maximum sequence number of the cached message in the last target cache block is assigned to the second indicator field. If the value of the first field in the last target cache block is the first value, or if the maximum sequence number of the cached message in the last target cache block is greater than the maximum message sequence number in the returned data packet, the minimum value between the maximum sequence number of the cached message in the last target cache block and the maximum message sequence number in the returned data packet is assigned to the second indicator field.

7. The method according to claim 5, characterized in that, After sending the return data packet to the client, the method further includes: The client receives a second message retrieval request, wherein the start sequence number in the second message retrieval request is equal to the sum of the value of the second indicator field in the returned data packet and 1; the second message retrieval request is sent by the client after detecting that the value of the first indicator field in the returned data packet is the first value.

8. The method according to any one of claims 1 to 4, characterized in that, Before reading a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and adding the read messages to the return data packet for the message retrieval request, the method further includes: Obtain the valid status information of the target cache block; If the valid status information indicates that the target cache block has expired, the database is requested to read a reference number of messages in the message stream with a sequence number not less than the minimum sequence number corresponding to the target cache block, based on the minimum sequence number corresponding to the target cache block, and cache the read messages in the target cache block; the reference number is the maximum number of messages that the target cache block is allowed to cache.

9. The method according to any one of claims 1 to 4, characterized in that, The message retrieval request also includes the target message stream identifier of the target message stream to which the requested message belongs; Before determining the target cache block by performing a cache block lookup in the cache based on the reference sequence number and the smallest sequence number of messages cached in each cache block in the cache, the method further includes: Based on the message stream identifier and the start sequence number in the message retrieval request, as well as the message stream identifier and the corresponding minimum sequence number of the message cached in each cache block in the cache, it is determined whether the message requested by the message retrieval request is located in the cache; The step of determining the target cache block by querying the cache block in the cache based on the reference sequence number and the smallest sequence number of the messages cached in each cache block in the cache includes: If it is determined that the message requested by the message retrieval request is located in the cache, a cache block query is performed in the cache based on the reference sequence number and the smallest sequence number of the message cached in each cache block in the cache to determine the target cache block.

10. The method according to any one of claims 1 to 4, characterized in that, The client is an enterprise instant messaging client, the message stream is an enterprise message stream, and the message retrieval request includes the enterprise identifier to which the client belongs; The step of determining the target cache block by querying the cache block in the cache based on the reference sequence number and the smallest sequence number of the messages cached in each cache block in the cache includes: Based on the reference sequence number and the minimum sequence number of the message cached in each cache block in the cache associated with the enterprise identifier, a cache block query is performed in the cache associated with the enterprise identifier to determine the target cache block.

11. A message retrieval device, characterized in that, include: The acquisition module is used to acquire message retrieval requests from clients; The message retrieval request includes the start sequence number of the requested messages and the number of messages to be retrieved; The query module is used to perform a cache block query in the cache based on the reference sequence number and the minimum sequence number of the messages cached in each cache block in the cache, to determine the target cache block; the target cache block is the cache block with the smallest sequence number interval between its corresponding minimum sequence number and the reference sequence number, and the minimum sequence number does not exceed the reference sequence number; a cache block caches messages from a message block, and the message block is determined by dividing the message stream stored in the database into blocks in ascending order of sequence number; the reference sequence number is initialized to the start sequence number; The reading module is used to read a target number of messages with a sequence number not less than the reference sequence number and the smallest sequence number from the target cache block, and add the read messages to the return data packet for the message retrieval request; The target quantity does not exceed the number of fetches; The response module is used to send the return data packet to the client if the number of messages in the return data packet reaches the number of fetches.

12. An electronic device, characterized in that, include: processor; A memory storing computer instructions that, when executed by the processor, implement the method as described in any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method as described in any one of claims 1-10.

14. A computer program product comprising computer instructions, characterized in that, When executed by a processor, the computer instructions implement the method described in any one of claims 1-10.