Skip to content

Commit fb8cdf6

Browse files
committed
Use LRU cache to track recent notebook execution times
1 parent 66d0f60 commit fb8cdf6

File tree

3 files changed

+3755
-3690
lines changed

3 files changed

+3755
-3690
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"dependencies": {
4848
"@jupyterlab/application": "^3.0.6",
4949
"@jupyterlab/notebook": "^3.1.0-beta.1",
50-
"@jupyterlab/settingregistry": "^3.0.3"
50+
"@jupyterlab/settingregistry": "^3.0.3",
51+
"lru-cache": "^6.0.0",
52+
"@types/lru-cache": "^5.1.1"
5153
},
5254
"devDependencies": {
5355
"@jupyterlab/builder": "^3.0.0",

src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { KernelError, Notebook, NotebookActions } from '@jupyterlab/notebook';
66
import { Cell } from '@jupyterlab/cells';
77
import { ISettingRegistry } from '@jupyterlab/settingregistry';
88
import { ICodeCellModel } from '@jupyterlab/cells';
9-
9+
import LRU from 'lru-cache';
1010
import { checkBrowserNotificationSettings } from './settings';
1111

1212
interface ICellExecutionMetadata {
@@ -106,9 +106,10 @@ const extension: JupyterFrontEndPlugin<void> = {
106106
const cellExecutionMetadataTable: {
107107
[cellId: string]: ICellExecutionMetadata;
108108
} = {};
109-
const recentNotebookExecutionTimes: {
110-
[notebookId: string]: Date;
111-
} = {};
109+
const recentNotebookExecutionTimes: LRU<string, Date> = new LRU({
110+
max: 500,
111+
maxAge: 1000 * 60 * 60 * 10 // 10 hours
112+
});
112113

113114
if (settingRegistry) {
114115
const setting = await settingRegistry.load(extension.id);
@@ -144,13 +145,13 @@ const extension: JupyterFrontEndPlugin<void> = {
144145
const notebookId = notebook.id;
145146
const scheduledTime = cellExecutionMetadataTable[cellId].scheduledTime;
146147
const recentExecutedCellTime =
147-
recentNotebookExecutionTimes[notebookId] || scheduledTime;
148+
recentNotebookExecutionTimes.get(notebookId) || scheduledTime;
148149
cellExecutionMetadataTable[cellId].startTime =
149150
scheduledTime >= recentExecutedCellTime
150151
? scheduledTime
151152
: recentExecutedCellTime;
152153
cellExecutionMetadataTable[cellId].endTime = cellEndTime;
153-
recentNotebookExecutionTimes[notebookId] = cellEndTime;
154+
recentNotebookExecutionTimes.set(notebookId, cellEndTime);
154155

155156
triggerNotification(
156157
cell,

0 commit comments

Comments
 (0)