mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Fix for history being saved too often
This commit is contained in:
parent
79a22b1f8d
commit
baa813c46f
@ -223,6 +223,7 @@ history_t & history_t::history_with_name(const wcstring &name) {
|
|||||||
|
|
||||||
history_t::history_t(const wcstring &pname) :
|
history_t::history_t(const wcstring &pname) :
|
||||||
name(pname),
|
name(pname),
|
||||||
|
unsaved_item_count(0),
|
||||||
mmap_start(NULL),
|
mmap_start(NULL),
|
||||||
mmap_length(0),
|
mmap_length(0),
|
||||||
birth_timestamp(time(NULL)),
|
birth_timestamp(time(NULL)),
|
||||||
@ -249,6 +250,7 @@ void history_t::add(const history_item_t &item)
|
|||||||
{
|
{
|
||||||
/* We have to add a new item */
|
/* We have to add a new item */
|
||||||
new_items.push_back(item);
|
new_items.push_back(item);
|
||||||
|
unsaved_item_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prevent the first write from always triggering a save */
|
/* Prevent the first write from always triggering a save */
|
||||||
@ -257,7 +259,7 @@ void history_t::add(const history_item_t &item)
|
|||||||
save_timestamp = now;
|
save_timestamp = now;
|
||||||
|
|
||||||
/* This might be a good candidate for moving to a background thread */
|
/* This might be a good candidate for moving to a background thread */
|
||||||
if((now > save_timestamp + SAVE_INTERVAL) || (new_items.size() >= SAVE_COUNT)) {
|
if((now > save_timestamp + SAVE_INTERVAL) || (unsaved_item_count >= SAVE_COUNT)) {
|
||||||
time_profiler_t profiler("save_internal");
|
time_profiler_t profiler("save_internal");
|
||||||
this->save_internal();
|
this->save_internal();
|
||||||
}
|
}
|
||||||
@ -764,6 +766,9 @@ void history_t::save_internal()
|
|||||||
|
|
||||||
/* Make sure we clear all nodes, since this doesn't happen automatically */
|
/* Make sure we clear all nodes, since this doesn't happen automatically */
|
||||||
lru.evict_all_nodes();
|
lru.evict_all_nodes();
|
||||||
|
|
||||||
|
/* We've saved everything, so we have no more unsaved items */
|
||||||
|
unsaved_item_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ok )
|
if( ok )
|
||||||
@ -781,6 +786,7 @@ void history_t::save(void) {
|
|||||||
void history_t::clear(void) {
|
void history_t::clear(void) {
|
||||||
scoped_lock locker(lock);
|
scoped_lock locker(lock);
|
||||||
new_items.clear();
|
new_items.clear();
|
||||||
|
unsaved_item_count = 0;
|
||||||
old_item_offsets.clear();
|
old_item_offsets.clear();
|
||||||
wcstring filename = history_filename(name, L"");
|
wcstring filename = history_filename(name, L"");
|
||||||
if (! filename.empty())
|
if (! filename.empty())
|
||||||
|
@ -98,6 +98,9 @@ private:
|
|||||||
/** New items. */
|
/** New items. */
|
||||||
std::vector<history_item_t> new_items;
|
std::vector<history_item_t> new_items;
|
||||||
|
|
||||||
|
/** How many items we've added without saving */
|
||||||
|
size_t unsaved_item_count;
|
||||||
|
|
||||||
/** The mmaped region for the history file */
|
/** The mmaped region for the history file */
|
||||||
const char *mmap_start;
|
const char *mmap_start;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user