File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
src/packages/frontend/frame-editors/time-travel-editor Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,25 @@ import {
36
36
import { FrameTree } from "../frame-tree/types" ;
37
37
import { export_to_json } from "./export-to-json" ;
38
38
import type { Document } from "@cocalc/sync/editor/generic/types" ;
39
+ import LRUCache from "lru-cache" ;
39
40
40
41
const EXTENSION = ".time-travel" ;
41
42
43
+ // We use a global cache so if user closes and opens file
44
+ // later it is fast.
45
+ const gitShowCache = new LRUCache < string , string > ( {
46
+ maxSize : 10 * 10 ** 6 , // 10MB
47
+ sizeCalculation : ( value , _key ) => {
48
+ return value . length + 1 ; // must be positive
49
+ } ,
50
+ } ) ;
51
+
42
52
/*interface FrameState {
43
53
version: number;
44
54
version0: number;
45
55
version1: number;
46
56
changes_mode: boolean;
57
+ git_mode: boolean;
47
58
}*/
48
59
49
60
export interface TimeTravelState extends CodeEditorState {
@@ -472,8 +483,13 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
472
483
if ( h == null ) {
473
484
return ;
474
485
}
486
+ const key = `${ h } :${ this . docpath } ` ;
487
+ if ( gitShowCache . has ( key ) ) {
488
+ return gitShowCache . get ( key ) ;
489
+ }
475
490
try {
476
491
const { stdout } = await this . gitCommand ( [ "show" ] , h ) ;
492
+ gitShowCache . set ( key , stdout ) ;
477
493
return stdout ;
478
494
} catch ( err ) {
479
495
this . set_error ( `${ err } ` ) ;
You can’t perform that action at this time.
0 commit comments