@@ -15,9 +15,16 @@ export function convertToActionType(action: string): SyncActionTypeEnum {
1515}
1616
1717export function convertLsnToInt ( lsn : string ) {
18+ // Convert timestamp to milliseconds since epoch
19+ const timestampMs = new Date ( ) . getTime ( ) ;
20+
21+ // Use LSN as a secondary sort key for events in the same millisecond
1822 const [ logFileNumber , byteOffset ] = lsn . split ( '/' ) ;
19- const hexString = logFileNumber + byteOffset ;
20- return parseInt ( hexString , 16 ) ;
23+ const lsnValue = parseInt ( logFileNumber + byteOffset , 16 ) ;
24+
25+ // Combine timestamp and LSN
26+ // Multiply timestamp by 1000 to leave room for LSN as sub-millisecond ordering
27+ return BigInt ( timestampMs ) * 1000n + BigInt ( lsnValue % 1000 ) ;
2128}
2229
2330export async function getWorkspaceId (
@@ -197,20 +204,40 @@ export async function getModelData(
197204 } ,
198205 } ,
199206 ConversationHistory : {
200- findUnique : ( ) => {
207+ findUnique : async ( ) => {
201208 if ( userId ) {
202- return prisma . conversationHistory . findFirst ( {
203- where : {
204- id : modelId ,
205- conversation : {
206- userId,
209+ const conversationHistory =
210+ await prisma . conversationHistory . findFirst ( {
211+ where : {
212+ id : modelId ,
213+ conversation : {
214+ userId,
215+ } ,
207216 } ,
208- } ,
209- } ) ;
217+ include : {
218+ conversation : true ,
219+ } ,
220+ } ) ;
221+
222+ return {
223+ ...conversationHistory ,
224+ recipientId : conversationHistory . conversation . userId ,
225+ } ;
210226 }
211- return prisma . conversationHistory . findUnique ( {
212- where : { id : modelId } ,
213- } ) ;
227+
228+ const conversationHistory = await prisma . conversationHistory . findUnique (
229+ {
230+ where : { id : modelId } ,
231+ include : {
232+ conversation : true ,
233+ } ,
234+ } ,
235+ ) ;
236+
237+ return {
238+ ...conversationHistory ,
239+ recipientId : conversationHistory . conversation . userId ,
240+ } ;
214241 } ,
215242 } ,
216243 Cycle : prisma . cycle ,
0 commit comments