File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed
components/DocumentView/CodeBlock Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,10 @@ type PositionedToken = ThemedToken & { start: number; end: number };
36
36
* This is done per invocation of the Cloudflare worker, so we can store it in-memory.
37
37
*/
38
38
let lineCount = 0 ;
39
- const LINE_LIMIT = 750 ;
39
+ let tokenCount = 0 ;
40
+ const LINE_LIMIT = 10000 ;
41
+
42
+ const runner = asyncMutexFunction ( ) ;
40
43
41
44
/**
42
45
* Highlight a code block while preserving inline elements.
@@ -62,17 +65,20 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
62
65
return a . start - b . start ;
63
66
} ) ;
64
67
68
+ const lineCountBefore = lineCount ;
65
69
const highlighter = await loadHighlighter ( ) ;
66
70
await loadHighlighterLanguage ( highlighter , langName ) ;
67
-
71
+
68
72
const lines = highlighter . codeToTokensBase ( code , {
69
73
lang : langName ,
70
74
tokenizeMaxLineLength : 120 ,
71
75
} ) ;
72
-
76
+
73
77
let currentIndex = 0 ;
74
-
78
+
79
+ console . log ( `${ block . key } ${ code . length } ${ lineCountBefore } ${ tokenCount } ` ) ;
75
80
return lines . map ( ( tokens , index ) => {
81
+ tokenCount += tokens . length ;
76
82
const lineBlock = block . nodes [ index ] ;
77
83
const result : HighlightToken [ ] = [ ] ;
78
84
Original file line number Diff line number Diff line change @@ -228,27 +228,30 @@ const UndefinedSymbol = Symbol('Undefined');
228
228
* where I/O cannot be performed on behalf of a different request.
229
229
*/
230
230
export function singleton < R > ( execute : ( ) => Promise < R > ) : ( ) => Promise < R > {
231
- let cachedResult : R | typeof UndefinedSymbol = UndefinedSymbol ;
231
+ let cachedResult : Promise < R > | typeof UndefinedSymbol = UndefinedSymbol ;
232
232
const states = new WeakMap < object , Promise < R > > ( ) ;
233
233
234
234
return async ( ) => {
235
+ console . log ( 'cachedResult' , cachedResult === UndefinedSymbol ) ;
235
236
if ( cachedResult !== UndefinedSymbol ) {
236
237
// Result is actually shared between requests
237
238
return cachedResult ;
238
239
}
239
240
240
241
// Promises are not shared between requests in Cloudflare Workers
241
- const ctx = await getGlobalContext ( ) ;
242
- const current = states . get ( ctx ) ;
243
- if ( current ) {
244
- return current ;
245
- }
242
+ // const ctx = await getGlobalContext();
243
+ // const current = states.get(ctx);
244
+ // if (current) {
245
+ // console.log(`states.get`)
246
+ // return current;
247
+ // }
246
248
247
249
const promise = execute ( ) ;
248
- states . set ( ctx , promise ) ;
250
+ console . log ( `states miss, set cachedResult` ) ;
251
+ cachedResult = promise ;
252
+ // states.set(ctx, promise);
249
253
250
254
const result = await promise ;
251
- cachedResult = result ;
252
255
return result ;
253
256
} ;
254
257
}
You can’t perform that action at this time.
0 commit comments