From 776f109b3a3844e5c27f3c132649f71799c85bc3 Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 14 May 2013 19:43:43 -0500 Subject: [PATCH] remove maintenance based on weights, remove AUTOJUMP_KEEP_ALL_ENTRIES --- README.md | 9 --------- bin/autojump | 43 +++++++------------------------------------ docs/autojump.1 | 15 --------------- docs/body.md | 9 --------- 4 files changed, 7 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index a0e74e2..db72c26 100644 --- a/README.md +++ b/README.md @@ -203,15 +203,6 @@ ADDITIONAL CONFIGURATION export AUTOJUMP_IGNORE_CASE=1 -- Prevent Database Entries' Decay - - Default behavior is to decay unused database entries slowly over - time. Eventually when database limits are hit and maintenance is - run, autojump will purge older less used entries. To prevent decay, - add the following variable in your \~/.bashrc: - - export AUTOJUMP_KEEP_ALL_ENTRIES=1 - - Prefer Symbolic Links Default behavior is to evaluate symbolic links into full paths as to diff --git a/bin/autojump b/bin/autojump index 2e2b38b..39f6d76 100755 --- a/bin/autojump +++ b/bin/autojump @@ -83,18 +83,6 @@ class Database: self.save() - def decay(self): - """ - Decay database entries. - """ - try: - items = self.data.iteritems() - except AttributeError: - items = self.data.items() - - for path, _ in items: - self.data[path] *= 0.9 - def get_weight(self, path): """ Return path weight. @@ -137,14 +125,14 @@ class Database: def maintenance(self): """ - Trims and decays database entries when exceeding settings. + If database has exceeded max_paths, remove bottom 10% entries. """ - if sum(self.data.values()) > self.config['max_weight']: - self.decay() if len(self.data) > self.config['max_paths']: - self.trim() + remove_cnt = int(0.1 * len(self.data)) + for path in sorted(self.data, key=self.data.get)[:remove_cnt]: + del self.data[path] - self.save() + self.save() def purge(self): """ @@ -198,27 +186,15 @@ class Database: print("Error while creating backup autojump file. (%s)" % ex, file=sys.stderr) - def trim(self, percent=0.1): - """ - If database has exceeded MAX_STORED_PATHS, removes bottom 10%. - """ - dirs = list(self.data.items()) - dirs.sort(key=operator.itemgetter(1)) - remove_cnt = int(percent * len(dirs)) - for path, _ in dirs[:remove_cnt]: - del self.data[path] - def set_defaults(): config = {} - config['version'] = 'release-v21.6.3' - config['max_weight'] = 1000 + config['version'] = 'release-v21.6.4' config['max_paths'] = 1000 config['separator'] = '__' config['home'] = os.path.expanduser('HOME') config['ignore_case'] = False - config['keep_entries'] = False config['keep_symlinks'] = False config['debug'] = False @@ -237,10 +213,6 @@ def parse_env(config): if config['data'] == config['home']: config['db'] = config['data'] + '/.autojump.txt' - if 'AUTOJUMP_KEEP_ALL_ENTRIES' in os.environ and \ - os.environ.get('AUTOJUMP_KEEP_ALL_ENTRIES') == '1': - config['keep_entries'] = True - if 'AUTOJUMP_IGNORE_CASE' in os.environ and \ os.environ.get('AUTOJUMP_IGNORE_CASE') == '1': config['ignore_case'] = True @@ -517,8 +489,7 @@ def main(): else: return 1 - if not config['keep_entries']: - db.maintenance() + db.maintenance() return 0 diff --git a/docs/autojump.1 b/docs/autojump.1 index fec5601..242eeed 100644 --- a/docs/autojump.1 +++ b/docs/autojump.1 @@ -155,21 +155,6 @@ export\ AUTOJUMP_IGNORE_CASE=1 .fi .RE .IP \[bu] 2 -Prevent Database Entries\[aq] Decay -.RS 2 -.PP -Default behavior is to decay unused database entries slowly over time. -Eventually when database limits are hit and maintenance is run, autojump -will purge older less used entries. -To prevent decay, add the following variable in your ~/.bashrc: -.IP -.nf -\f[C] -export\ AUTOJUMP_KEEP_ALL_ENTRIES=1 -\f[] -.fi -.RE -.IP \[bu] 2 Prefer Symbolic Links .RS 2 .PP diff --git a/docs/body.md b/docs/body.md index 2e17dd0..f44070e 100644 --- a/docs/body.md +++ b/docs/body.md @@ -73,15 +73,6 @@ ADDITIONAL CONFIGURATION export AUTOJUMP_IGNORE_CASE=1 -- Prevent Database Entries' Decay - - Default behavior is to decay unused database entries slowly over - time. Eventually when database limits are hit and maintenance is - run, autojump will purge older less used entries. To prevent decay, - add the following variable in your \~/.bashrc: - - export AUTOJUMP_KEEP_ALL_ENTRIES=1 - - Prefer Symbolic Links Default behavior is to evaluate symbolic links into full paths as to