- speedup history lookup

- fix cleanup of recent files


SVN revision: 48549
This commit is contained in:
Hannes Janetzek 2010-05-02 15:46:02 +00:00
parent ae97144aa9
commit fc31b50109
3 changed files with 100 additions and 67 deletions

View File

@ -23,6 +23,9 @@
#define ONE_DAY 86400.0
#define TIME_FACTOR(_now) (1.0 - (evry_hist->begin / _now)) / 1000000000000000.0
/* #undef DBG
* #define DBG(...) ERR(__VA_ARGS__) */
typedef struct _Plugin Plugin;
typedef struct _Data Data;
typedef struct _Module_Config Module_Config;
@ -338,6 +341,9 @@ _append_files(Plugin *p)
{
if (cnt >= MAX_SHOWN) break;
if (p->dirs_only && !EVRY_ITEM(file)->browseable)
continue;
if (p->input && (match = evry_fuzzy_match(EVRY_ITEM(file)->label, p->input)))
{
EVRY_ITEM(file)->fuzzy_match = match;
@ -457,7 +463,7 @@ _scan_end_func(void *data)
file->mime = eina_stringshare_ref(hi->data);
DBG("cached: %s %s", file->mime, file->path);
hi->transient = 0;
item->hi = hi;
/* remember that item was found */
if (hi->count == 1)
{
@ -528,6 +534,7 @@ _scan_end_func(void *data)
hi->last_used -= (ONE_DAY * 6.0);
hi->usage = TIME_FACTOR(hi->last_used);
hi->data = eina_stringshare_ref(file->mime);
item->hi = hi;
}
else
{
@ -819,6 +826,7 @@ _hist_end_func(void *data)
if (!it->data)
{
p->hist_added = eina_list_remove_list(p->hist_added, l);
evry_item_free(it);
continue;
}
@ -841,8 +849,7 @@ _hist_end_func(void *data)
evry_item_ref(it);
if (!p->dirs_only || it->browseable)
p->files = eina_list_append(p->files, it);
p->files = eina_list_append(p->files, it);
}
p->thread2 = NULL;
@ -999,7 +1006,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
}
int len = strlen(p->directory);
len = (len == 1) ? len : len+1;
p->input = eina_stringshare_add(input + len);
}
else if (p->directory && input && !strncmp(input, "..", 2))
@ -1040,9 +1047,10 @@ _fetch(Evry_Plugin *plugin, const char *input)
_read_directory(p);
p->command = CMD_SHOW_HIDDEN;
return 0;
}
p->input = eina_stringshare_add(input + 1);
p->input = eina_stringshare_add(input);
}
else if (p->command)
{
@ -1062,24 +1070,26 @@ _fetch(Evry_Plugin *plugin, const char *input)
_read_directory(p);
p->command = CMD_NONE;
return 0;
}
if (p->show_recent && input)
if (p->show_recent)
{
if ((!p->parent && !p->command && !p->hist_added) &&
(((_conf->search_recent || _conf->search_cache) && strlen(input) > 2) ||
(((_conf->search_recent || _conf->search_cache) &&
(input && strlen(input) > 2)) ||
(_conf->show_recent)))
{
eina_hash_foreach(evry_hist->subjects, _hist_items_add_cb, p);
p->thread2 = ecore_thread_run(_hist_func, _hist_end_func, _hist_cancel_func, p);
}
else if (p->hist_added && (strlen(input) < 3) && (_conf->search_recent || _conf->search_cache))
else if ((_conf->search_recent || _conf->search_cache) &&
(p->hist_added && (!input || (strlen(input) < 3))))
{
EINA_LIST_FREE(p->hist_added, file)
{
p->files = eina_list_remove(p->files, file);
evry_item_free(EVRY_ITEM(file));
evry_item_free(EVRY_ITEM(file));
}
}
}
@ -1090,7 +1100,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
_append_files(p);
if (!EVRY_PLUGIN(p)->items)
return 0;
return 1;
if (!p->parent && _conf->show_recent)
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);

View File

@ -3,7 +3,7 @@
#include "e.h"
#define EVRY_API_VERSION 10
#define EVRY_API_VERSION 11
#define EVRY_ACTION_OTHER 0
#define EVRY_ACTION_FINISHED 1
@ -173,6 +173,7 @@ struct _Evry_Item
Evry_Plugin *plugin;
int ref;
double usage;
History_Item *hi;
};
struct _Evry_Action

View File

@ -316,14 +316,18 @@ evry_history_add(Eina_Hash *hist, Evry_Item *it, const char *ctxt, const char *i
hi->context = eina_stringshare_ref(ctxt);
}
if (input)
if (input && hi->input)
{
if (hi->input)
eina_stringshare_del(hi->input);
hi->input = eina_stringshare_add(input);
if (strncmp(hi->input, input, strlen(input)))
{
eina_stringshare_del(hi->input);
hi->input = eina_stringshare_add(input);
}
}
else if (input)
{
hi->input = eina_stringshare_add(input);
}
}
return hi;
}
@ -332,78 +336,96 @@ EAPI int
evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt)
{
History_Entry *he;
History_Item *hi;
History_Item *hi = NULL;
Eina_List *l;
int rem_ctxt = 1;
it->usage = 0.0;
const char *type;
if (!it->plugin->history)
return 0;
it->usage = 0.0;
if (!(he = eina_hash_find(hist, (it->id ? it->id : it->label))))
return 0;
if (it->type == EVRY_TYPE_ACTION)
if (!it->hi)
{
GET_ACTION(act, it);
if (!act->remember_context)
rem_ctxt = 0;
}
EINA_LIST_FOREACH(he->items, l, hi)
{
if (hi->plugin != it->plugin->name)
continue;
if (!(he = eina_hash_find(hist, (it->id ? it->id : it->label))))
return 0;
if (evry_conf->history_sort_mode == 0)
type = evry_type_get(it->type);
if (it->type == EVRY_TYPE_ACTION)
{
GET_ACTION(act, it);
if (!act->remember_context)
rem_ctxt = 0;
}
EINA_LIST_FOREACH(he->items, l, hi)
{
if (hi->plugin != it->plugin->name)
continue;
if (!input || !hi->input)
if (hi->type != type)
continue;
if (rem_ctxt && ctxt && (hi->context != ctxt))
{
it->hi = hi;
continue;
}
it->hi = hi;
break;
}
}
if (!it->hi)
return 0;
hi = it->hi;
if (evry_conf->history_sort_mode == 0)
{
if (!input || !hi->input)
{
it->usage += hi->usage * hi->count;
}
else
{
/* higher priority for exact matches */
if (!strncmp(input, hi->input, strlen(input)))
{
it->usage += hi->usage * hi->count;
}
else
if (!strncmp(input, hi->input, strlen(hi->input)))
{
/* higher priority for exact matches */
if (!strncmp(input, hi->input, strlen(input)))
{
it->usage += hi->usage * hi->count;
}
if (!strncmp(input, hi->input, strlen(hi->input)))
{
it->usage += hi->usage * hi->count;
}
it->usage += hi->usage * hi->count;
}
if (ctxt && hi->context &&
(hi->context == ctxt))
it->usage += hi->usage * hi->count * 10;
}
else if (evry_conf->history_sort_mode == 1)
if (ctxt && hi->context && (hi->context == ctxt))
{
it->usage = hi->count * (hi->last_used / 10000000000.0);
it->usage += hi->usage * hi->count * 10;
}
else if (evry_conf->history_sort_mode == 2)
{
if (hi->last_used > it->usage)
it->usage = hi->last_used;
}
/* XXX remopve just for update */
if (!rem_ctxt && hi->context)
{
eina_stringshare_del(hi->context);
hi->context = NULL;
}
if (ctxt != hi->context)
it->usage /= 2.0;
}
else if (evry_conf->history_sort_mode == 1)
{
it->usage = hi->count * (hi->last_used / 10000000000.0);
if (ctxt && hi->context && (hi->context == ctxt))
{
it->usage += hi->usage * hi->count * 10;
}
}
else if (evry_conf->history_sort_mode == 2)
{
if (hi->last_used > it->usage)
it->usage = hi->last_used;
}
if (it->usage > 0.0)
return 1;
it->usage = -1;
return 0;
}