[gnome-usage/tracker-powered-storage-view-wip: 102/103] storage: Significantly increase loading speed of items in storage
- From: Petr Štětka <pstetka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage/tracker-powered-storage-view-wip: 102/103] storage: Significantly increase loading speed of items in storage
- Date: Tue, 2 Apr 2019 12:28:23 +0000 (UTC)
commit 73fbec38ba26d1b55c8ea08c939c91593b4c5cac
Author: Petr Štětka <pstetka redhat com>
Date: Tue Oct 9 14:39:56 2018 +0200
storage: Significantly increase loading speed of items in storage
src/storage/storage-graph.vala | 18 +++++-----
src/storage/storage-view-item.vala | 2 ++
src/storage/storage-view-row.vala | 26 ++++++++-------
src/storage/storage-view.vala | 66 +++++++++----------------------------
src/storage/tracker-controller.vala | 40 +++++++++++-----------
5 files changed, 61 insertions(+), 91 deletions(-)
---
diff --git a/src/storage/storage-graph.vala b/src/storage/storage-graph.vala
index e1f3873..e147df4 100644
--- a/src/storage/storage-graph.vala
+++ b/src/storage/storage-graph.vala
@@ -25,11 +25,11 @@ namespace Usage
public class StorageGraph : Gtk.DrawingArea
{
private unowned List<StorageViewItem> selected_items;
- private GLib.ListStore _model;
+ private unowned GLib.ListStore _model;
private uint64 selected_size = 0;
private bool root { private set; get; }
- public GLib.ListStore model {
+ public unowned GLib.ListStore model {
set {
_model = value;
this.draw.connect(draw_storage_graph);
@@ -73,7 +73,7 @@ namespace Usage
this.queue_draw();
}
- private void draw_circle(Cairo.Context context, GLib.ListStore model, double x, double y, double
radius, int section, Circle circle)
+ private void draw_circle(Cairo.Context context, double x, double y, double radius, int section,
Circle circle)
{
double start_angle = 0;
double final_angle = - Math.PI / 2.0;
@@ -94,10 +94,10 @@ namespace Usage
shown_items_number = shown_items_number + 1;
}
- if(shown_items_number < 3)
- shown_items_number = 3;
-
if(shown_items_number > 1) {
+ if(shown_items_number < 3)
+ shown_items_number = 3;
+
for(int i = 0; i < model.get_n_items(); i++)
{
var item = model.get_item(i) as StorageViewItem;
@@ -112,8 +112,10 @@ namespace Usage
Gdk.RGBA fill_color = base_color;
- if(!root)
+ if(!root) {
fill_color = Utils.generate_color(base_color, i, shown_items_number, true);
+ item.color = fill_color;
+ }
if(selected_items.find(item) != null)
item_radius += radius / 6;
@@ -168,7 +170,7 @@ namespace Usage
x = width / 2.0;
y = height / 2.0;
- draw_circle(context, model, x, y, radius, 0, Circle.BASE);
+ draw_circle(context, x, y, radius, 0, Circle.BASE);
draw_selected_size_text(context);
return true;
diff --git a/src/storage/storage-view-item.vala b/src/storage/storage-view-item.vala
index 86a167a..e7dfe21 100644
--- a/src/storage/storage-view-item.vala
+++ b/src/storage/storage-view-item.vala
@@ -16,11 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Felipe Borges <felipeborges gnome org>
+ * Petr Štětka <pstetka redhat com>
*/
public class Usage.StorageViewItem : GLib.Object {
public double percentage { set; get; }
public bool loaded { get; set; default = false; }
+ public Gdk.RGBA color { get; set; }
public string uri;
public string name;
diff --git a/src/storage/storage-view-row.vala b/src/storage/storage-view-row.vala
index 929cade..8c3974c 100644
--- a/src/storage/storage-view-row.vala
+++ b/src/storage/storage-view-row.vala
@@ -66,20 +66,24 @@ public class Usage.StorageViewRow : Gtk.ListBoxRow {
public signal void check_button_toggled();
public StorageViewItem item;
- public Gdk.RGBA default_color;
public StorageViewRow.from_item (StorageViewItem item) {
this.item = item;
- title.label = item.name;
- size_label.label = Utils.format_size_values (item.size);
+ var tag_style_context = tag.get_style_context();
+ tag_style_context.add_class (item.style_class);
+ item.color = tag_style_context.get_background_color(tag_style_context.get_state());
- tag.get_style_context ().add_class (item.style_class);
check_button.visible = item.show_check_button;
check_button.toggled.connect(() => {
check_button_toggled();
});
+ item.notify.connect(() => {
+ set_up();
+ });
+ set_up();
+
if (item.type == FileType.DIRECTORY || item.custom_type != null)
tag.width_request = tag.height_request = 20;
@@ -98,21 +102,21 @@ public class Usage.StorageViewRow : Gtk.ListBoxRow {
}
});
}
-
- default_color = tag.get_style_context().get_background_color(get_style_context().get_state());
}
- public void colorize(uint order, uint all_count) {
- if(order == 0)
- return;
+ private void set_up() {
+ title.label = item.name;
+ size_label.label = Utils.format_size_values (item.size);
+ change_color(item.color);
+ }
- var result_color = Utils.generate_color(default_color, order, all_count, true);
+ private void change_color(Gdk.RGBA color) {
var css_provider = new Gtk.CssProvider();
tag.get_style_context().add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
var css =
@".row-tag {
- background: $result_color;
+ background: $color;
}";
try {
diff --git a/src/storage/storage-view.vala b/src/storage/storage-view.vala
index cee8852..47e8832 100644
--- a/src/storage/storage-view.vala
+++ b/src/storage/storage-view.vala
@@ -69,7 +69,6 @@ public class Usage.NewStorageView : Usage.View {
private List<StorageViewItem> selected_items = new List<StorageViewItem> ();
private Queue<List> selected_items_stack = new Queue<List> ();
private Queue<StorageViewItem> actual_item = new Queue<StorageViewItem> ();
- private HashTable<StorageViewItem, StorageViewRow> rows_table = new HashTable<StorageViewItem,
StorageViewRow> (direct_hash, direct_equal);
construct {
name = "STORAGE";
@@ -83,7 +82,6 @@ public class Usage.NewStorageView : Usage.View {
query_builder = new StorageQueryBuilder ();
controller = new TrackerController (connection);
- controller.refresh_model.connect(refresh_listbox);
actionbar.refresh_listbox.connect(() => {
var item = actual_item.peek_head();
@@ -94,7 +92,7 @@ public class Usage.NewStorageView : Usage.View {
if(listbox.get_depth() >= 1) {
selected_items_stack.push_head((owned) selected_items);
actual_item.push_head(item);
- present_dir.begin (item.uri, item.dir);
+ present_dir.begin (item.uri, item.dir, cancellable);
}
else
populate_view.begin ();
@@ -121,11 +119,10 @@ public class Usage.NewStorageView : Usage.View {
if(storage_row.item.custom_type == "up-folder") {
stack_listbox_up();
} else if (storage_row.item.type == FileType.DIRECTORY) {
- rows_table.remove_all();
selected_items_stack.push_head((owned) selected_items);
actual_item.push_head(storage_row.item);
clear_selected_items();
- present_dir.begin (storage_row.item.uri, storage_row.item.dir);
+ present_dir.begin (storage_row.item.uri, storage_row.item.dir, cancellable);
} else if (storage_row.item.custom_type != null) {
row_popover.present(storage_row);
} else {
@@ -160,10 +157,10 @@ public class Usage.NewStorageView : Usage.View {
if(listbox.get_depth() == 0)
populate_view.begin ();
else
- present_dir.begin (item.uri, item.dir);
+ present_dir.begin (item.uri, item.dir, cancellable);
}
else
- refresh_listbox();
+ graph.model = (ListStore) listbox.get_model();
}
private string get_user_special_dir_path (UserDirectory dir) {
@@ -190,33 +187,11 @@ public class Usage.NewStorageView : Usage.View {
if(item.custom_type == "available-graph")
return new Gtk.ListBoxRow();
- rows_table.insert(item, row);
+ graph.model = (ListStore) listbox.get_model();
return row;
}
- public void refresh_listbox() {
- var rows_number = 0;
- var model = listbox.get_model();
- graph.model = (ListStore) model;
-
- if(listbox.get_depth() > 1) {
- for(int i = 0; i < model.get_n_items(); i++) {
- if((model.get_item(i) as StorageViewItem).percentage > MIN_PERCENTAGE_SHOWN_FILES)
- rows_number++;
- }
-
- if(rows_number < 3)
- rows_number = 3;
-
- for(int i = 0; i < model.get_n_items(); i++) {
- var item = model.get_item(i) as StorageViewItem;
- var row = rows_table.get(item);
- row.colorize(i, rows_number);
- }
- }
- }
-
- private async void present_dir (string uri, UserDirectory? dir) {
+ private async void present_dir (string uri, UserDirectory? dir, Cancellable cancellable) {
if (connection == null || cancellable.is_cancelled())
return;
@@ -225,31 +200,21 @@ public class Usage.NewStorageView : Usage.View {
var item = StorageViewItem.from_file (file);
item.custom_type = "up-folder";
item.dir = dir;
+ model.insert(0, item);
controller.set_model(model);
controller.enumerate_children.begin(uri, dir, cancellable, (obj, res) => {
- try {
- item.loaded = controller.enumerate_children.end(res);
- } catch (GLib.Error error) {
- warning(error.message);
+ if(!cancellable.is_cancelled()) {
+ var up_folder_item = model.get_item(0) as StorageViewItem;
+ up_folder_item.size = controller.enumerate_children.end(res);
+ up_folder_item.loaded = true;
+ graph.model = model;
}
});
- controller.get_file_size.begin (item.uri, (obj, res) => {
- try {
- item.size = controller.get_file_size.end (res);
- } catch (GLib.Error error) {
- warning(error.message);
- }
-
- item.percentage = item.size * 100 / (double) total_size;
- model.insert(0, item);
-
- listbox.push (new Gtk.ListBoxRow(), model, create_file_row);
-
- if(!cancellable.is_cancelled())
- graph.model = model;
- });
+ listbox.push (new Gtk.ListBoxRow(), model, create_file_row);
+ if(!cancellable.is_cancelled())
+ graph.model = model;
}
private void setup_header_label () {
@@ -317,7 +282,6 @@ public class Usage.NewStorageView : Usage.View {
item.percentage = item.size * 100 / (double) total_size;
item.custom_type = "root_item";
model.insert (1, item);
- refresh_listbox();
} catch (GLib.Error error) {
warning (error.message);
}
diff --git a/src/storage/tracker-controller.vala b/src/storage/tracker-controller.vala
index f9f3905..bbc13ec 100644
--- a/src/storage/tracker-controller.vala
+++ b/src/storage/tracker-controller.vala
@@ -21,8 +21,6 @@
using Tracker;
public class Usage.TrackerController : GLib.Object {
- public signal void refresh_model();
-
private Sparql.Connection connection;
private StorageQueryBuilder query_builder;
private GLib.ListStore model;
@@ -39,21 +37,22 @@ public class Usage.TrackerController : GLib.Object {
this.model = model;
}
- public async bool enumerate_children (string uri, UserDirectory? dir, Cancellable cancellable) throws
GLib.Error {
+ public async uint64 enumerate_children (string uri, UserDirectory? dir, Cancellable cancellable) {
var query = query_builder.enumerate_children (uri);
- var worker = yield new TrackerWorker (connection, query);
- string n_uri = null;
- string file_type = null;
+ uint64 uri_size = 0;
+ try {
- var parent = File.new_for_uri (uri);
- uint64 parent_size = 1;
- if (parent != null) {
- parent_size = yield get_file_size (uri);
- }
+ var worker = yield new TrackerWorker (connection, query);
+ string n_uri = null;
+ string file_type = null;
+
+ var parent = File.new_for_uri (uri);
+ uint64 parent_size = 1;
+ if (parent != null)
+ parent_size = yield get_file_size (uri);
- while (yield worker.fetch_next (out n_uri, out file_type)) {
- try {
+ while (yield worker.fetch_next (out n_uri, out file_type)) {
if(!cancellable.is_cancelled()) {
var file = File.new_for_uri (n_uri);
var item = StorageViewItem.from_file (file);
@@ -69,31 +68,30 @@ public class Usage.TrackerController : GLib.Object {
}
item.percentage = item.size*100/(double)parent_size;
+ uri_size += item.size;
model.insert_sorted (item, (a, b) => {
var item_a = a as StorageViewItem;
var item_b = b as StorageViewItem;
- if (item_a.size > item_b.size) {
+ if (item_a.custom_type == "up-folder" || item_a.size > item_b.size) {
return -1;
}
- if (item_b.size > item_a.size) {
+ if (item_b.custom_type == "up-folder" || item_b.size > item_a.size) {
return 1;
}
return 0;
});
-
- refresh_model();
} else
- return false;
- } catch (GLib.Error error) {
- warning (error.message);
+ return uri_size;
}
+ } catch (GLib.Error error) {
+ warning (error.message);
}
- return true;
+ return uri_size;
}
private uint64 get_g_file_size (string uri) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]