[sql] fix spurious loading bar flash while searching

This commit is contained in:
Timothy Stack 2015-09-03 21:23:29 -07:00
parent 399c78d86d
commit 3c0d78d28e
4 changed files with 47 additions and 37 deletions

View File

@ -38,6 +38,32 @@
using namespace std; using namespace std;
static int sql_progress(const struct log_cursor &lc)
{
static sig_atomic_t sql_counter = 0;
size_t total = lnav_data.ld_log_source.text_line_count();
off_t off = lc.lc_curr_line;
if (lnav_data.ld_window == NULL) {
return 0;
}
if (!lnav_data.ld_looping) {
return 1;
}
if (ui_periodic_timer::singleton().time_to_update(sql_counter)) {
lnav_data.ld_bottom_source.update_loading(off, total);
lnav_data.ld_top_source.update_time();
lnav_data.ld_status[LNS_TOP].do_update();
lnav_data.ld_status[LNS_BOTTOM].do_update();
refresh();
}
return 0;
}
string execute_from_file(const string &path, int line_number, char mode, const string &cmdline); string execute_from_file(const string &path, int line_number, char mode, const string &cmdline);
string execute_command(string cmdline) string execute_command(string cmdline)
@ -94,6 +120,7 @@ string execute_sql(string sql, string &alt_msg)
hs.get_displayed_buckets().clear(); hs.get_displayed_buckets().clear();
dls.clear(); dls.clear();
dls.dls_stmt_str = stmt_str; dls.dls_stmt_str = stmt_str;
sql_progress_guard progress_guard(sql_progress);
retcode = sqlite3_prepare_v2(lnav_data.ld_db.in(), retcode = sqlite3_prepare_v2(lnav_data.ld_db.in(),
stmt_str.c_str(), stmt_str.c_str(),
-1, -1,

View File

@ -2202,32 +2202,6 @@ static void setup_highlights(textview_curses::highlight_map_t &hm)
false, view_colors::VCR_VARIABLE); false, view_colors::VCR_VARIABLE);
} }
int sql_progress(const struct log_cursor &lc)
{
static sig_atomic_t sql_counter = 0;
size_t total = lnav_data.ld_log_source.text_line_count();
off_t off = lc.lc_curr_line;
if (lnav_data.ld_window == NULL) {
return 0;
}
if (!lnav_data.ld_looping) {
return 1;
}
if (ui_periodic_timer::singleton().time_to_update(sql_counter)) {
lnav_data.ld_bottom_source.update_loading(off, total);
lnav_data.ld_top_source.update_time();
lnav_data.ld_status[LNS_TOP].do_update();
lnav_data.ld_status[LNS_BOTTOM].do_update();
refresh();
}
return 0;
}
static void print_errors(vector<string> error_list) static void print_errors(vector<string> error_list)
{ {
for (std::vector<std::string>::iterator iter = error_list.begin(); for (std::vector<std::string>::iterator iter = error_list.begin();
@ -2496,8 +2470,7 @@ int main(int argc, char *argv[])
lnav_data.ld_vtab_manager = lnav_data.ld_vtab_manager =
new log_vtab_manager(lnav_data.ld_db, new log_vtab_manager(lnav_data.ld_db,
lnav_data.ld_views[LNV_LOG], lnav_data.ld_views[LNV_LOG],
lnav_data.ld_log_source, lnav_data.ld_log_source);
sql_progress);
{ {
auto_mem<char, sqlite3_free> errmsg; auto_mem<char, sqlite3_free> errmsg;

View File

@ -39,7 +39,7 @@ using namespace std;
static struct log_cursor log_cursor_latest; static struct log_cursor log_cursor_latest;
static sql_progress_callback_t vtab_progress_callback; sql_progress_callback_t log_vtab_progress_callback;
static const char *type_to_string(int type) static const char *type_to_string(int type)
{ {
@ -224,7 +224,7 @@ static int vt_next(sqlite3_vtab_cursor *cur)
do { do {
log_cursor_latest = vc->log_cursor; log_cursor_latest = vc->log_cursor;
if (((log_cursor_latest.lc_curr_line % 1024) == 0) && if (((log_cursor_latest.lc_curr_line % 1024) == 0) &&
vtab_progress_callback(log_cursor_latest)) { log_vtab_progress_callback(log_cursor_latest)) {
break; break;
} }
done = vt->vi->next(vc->log_cursor, *vt->lss); done = vt->vi->next(vc->log_cursor, *vt->lss);
@ -645,8 +645,8 @@ static int progress_callback(void *ptr)
{ {
int retval = 0; int retval = 0;
if (vtab_progress_callback != NULL) { if (log_vtab_progress_callback != NULL) {
retval = vtab_progress_callback(log_cursor_latest); retval = log_vtab_progress_callback(log_cursor_latest);
} }
return retval; return retval;
@ -654,12 +654,10 @@ static int progress_callback(void *ptr)
log_vtab_manager::log_vtab_manager(sqlite3 *memdb, log_vtab_manager::log_vtab_manager(sqlite3 *memdb,
textview_curses &tc, textview_curses &tc,
logfile_sub_source &lss, logfile_sub_source &lss)
sql_progress_callback_t pc)
: vm_db(memdb), vm_textview(tc), vm_source(lss) : vm_db(memdb), vm_textview(tc), vm_source(lss)
{ {
sqlite3_create_module(this->vm_db, "log_vtab_impl", &vtab_module, this); sqlite3_create_module(this->vm_db, "log_vtab_impl", &vtab_module, this);
vtab_progress_callback = pc;
sqlite3_progress_handler(memdb, 32, progress_callback, NULL); sqlite3_progress_handler(memdb, 32, progress_callback, NULL);
} }

View File

@ -164,14 +164,26 @@ protected:
typedef int (*sql_progress_callback_t)(const log_cursor &lc); typedef int (*sql_progress_callback_t)(const log_cursor &lc);
extern sql_progress_callback_t log_vtab_progress_callback;
class sql_progress_guard {
public:
sql_progress_guard(sql_progress_callback_t cb) {
log_vtab_progress_callback = cb;
};
~sql_progress_guard() {
log_vtab_progress_callback = NULL;
};
};
class log_vtab_manager { class log_vtab_manager {
public: public:
typedef std::map<intern_string_t, log_vtab_impl *>::const_iterator iterator; typedef std::map<intern_string_t, log_vtab_impl *>::const_iterator iterator;
log_vtab_manager(sqlite3 *db, log_vtab_manager(sqlite3 *db,
textview_curses &tc, textview_curses &tc,
logfile_sub_source &lss, logfile_sub_source &lss);
sql_progress_callback_t);
textview_curses *get_view() const { return &this->vm_textview; }; textview_curses *get_view() const { return &this->vm_textview; };