Skip to content

Commit 3462c8e

Browse files
committed
Limit the history to 20 entries per window
Reduces the amount of work and API calls we need to do before showing the panel while at the same time reducing the amount of data we store in the workspace. Going back more than 20 tabs in the stack is very unlikely and the only remaining downside is that we will have no history at all after the user closed these 20 tabs, but in that case it is questionable to assume that the user would return exactly to the work they did before closing these 20 tabs anyway. A configuration option is not added because this seems like a reasonable default. If configuration is wanted, the user can override our new `constants.py` file instead. Closes #4
1 parent 08f3c38 commit 3462c8e

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

plugin/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TAB_HISTORY_LIMIT = 20

plugin/history.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, cast
44

55
from ._compat import sublime
6+
from .constants import TAB_HISTORY_LIMIT
67
from .sheets import SheetIdentity, find_sheet_by_identity_and_group, sheet_identity
78
from .state import (
89
GroupSelectionState,
@@ -238,6 +239,8 @@ def prune_history_stack(
238239
updated_stack: list[GroupSelectionState] = []
239240
seen_identities: list[SheetIdentity] = list(removed_identities or [])
240241
for group_state in group_state_stack:
242+
if len(updated_stack) >= TAB_HISTORY_LIMIT:
243+
break
241244
pruned_group_state = prune_group_state(
242245
group_state,
243246
seen_identities,

plugin/mru.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses import dataclass
44

55
from .captions import caption_for_sheet_identities
6+
from .constants import TAB_HISTORY_LIMIT
67
from .sheets import SheetIdentity, sheet_identity
78
from .state import GroupSelectionState, SheetSelectionHistory
89

@@ -30,6 +31,8 @@ def collect_entries(window, history: SheetSelectionHistory) -> list[Entry]:
3031
seen_identities.update(_selection_identity_keys(group_state))
3132

3233
for sheet in _non_transient_sheets_in_group(window, active_group):
34+
if len(entries) >= TAB_HISTORY_LIMIT:
35+
break
3336
identity = _identity_key(sheet_identity(sheet, window))
3437
if identity in seen_identities:
3538
continue

0 commit comments

Comments
 (0)