mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2025-12-21 16:09:41 +01:00
slight optimization of loading/deleting data
This commit is contained in:
@@ -43,6 +43,9 @@ class Application(Gtk.Application):
|
|||||||
FAV_MODEL_NAME = "fav_list_store"
|
FAV_MODEL_NAME = "fav_list_store"
|
||||||
BQ_MODEL_NAME = "bouquets_tree_store"
|
BQ_MODEL_NAME = "bouquets_tree_store"
|
||||||
|
|
||||||
|
DEL_FACTOR = 50 # Batch size to delete in one pass.
|
||||||
|
FAV_FACTOR = DEL_FACTOR * 2
|
||||||
|
|
||||||
_TV_TYPES = ("TV", "TV (HD)", "TV (UHD)", "TV (H264)")
|
_TV_TYPES = ("TV", "TV (HD)", "TV (UHD)", "TV (H264)")
|
||||||
|
|
||||||
# Dynamically active elements depending on the selected view
|
# Dynamically active elements depending on the selected view
|
||||||
@@ -605,13 +608,17 @@ class Application(Gtk.Application):
|
|||||||
itrs = [model.get_iter(path) for path in paths]
|
itrs = [model.get_iter(path) for path in paths]
|
||||||
rows = [model[in_itr][:] for in_itr in itrs]
|
rows = [model[in_itr][:] for in_itr in itrs]
|
||||||
|
|
||||||
if model_name == self.FAV_MODEL_NAME:
|
if len(itrs) > self.DEL_FACTOR:
|
||||||
next(self.remove_favs(itrs, model), False)
|
self._wait_dialog.show("Deleting data...")
|
||||||
elif model_name == self.BQ_MODEL_NAME:
|
|
||||||
self.delete_bouquets(itrs, model)
|
|
||||||
elif model_name == self.SERVICE_MODEL_NAME:
|
|
||||||
next(self.delete_services(itrs, model, rows), False)
|
|
||||||
|
|
||||||
|
if model_name == self.FAV_MODEL_NAME:
|
||||||
|
gen = self.remove_favs(itrs, model)
|
||||||
|
elif model_name == self.BQ_MODEL_NAME:
|
||||||
|
gen = self.delete_bouquets(itrs, model)
|
||||||
|
elif model_name == self.SERVICE_MODEL_NAME:
|
||||||
|
gen = self.delete_services(itrs, model, rows)
|
||||||
|
|
||||||
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
||||||
self.on_view_focus(view)
|
self.on_view_focus(view)
|
||||||
|
|
||||||
return rows
|
return rows
|
||||||
@@ -621,18 +628,23 @@ class Application(Gtk.Application):
|
|||||||
if self._bq_selected:
|
if self._bq_selected:
|
||||||
fav_bouquet = self._bouquets.get(self._bq_selected, None)
|
fav_bouquet = self._bouquets.get(self._bq_selected, None)
|
||||||
if fav_bouquet:
|
if fav_bouquet:
|
||||||
for itr in itrs:
|
for index, itr in enumerate(itrs):
|
||||||
del fav_bouquet[int(model.get_path(itr)[0])]
|
del fav_bouquet[int(model.get_path(itr)[0])]
|
||||||
self._fav_model.remove(itr)
|
self._fav_model.remove(itr)
|
||||||
|
if index % self.DEL_FACTOR == 0:
|
||||||
|
yield True
|
||||||
self.update_fav_num_column(model)
|
self.update_fav_num_column(model)
|
||||||
|
|
||||||
|
self._wait_dialog.hide()
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
def delete_services(self, itrs, model, rows):
|
def delete_services(self, itrs, model, rows):
|
||||||
""" Deleting services """
|
""" Deleting services """
|
||||||
srv_itrs = [self._services_model_filter.convert_iter_to_child_iter(
|
for index, s_itr in enumerate([self._services_model_filter.convert_iter_to_child_iter(
|
||||||
model.convert_iter_to_child_iter(itr)) for itr in itrs]
|
model.convert_iter_to_child_iter(itr)) for itr in itrs]):
|
||||||
for s_itr in srv_itrs:
|
|
||||||
self._services_model.remove(s_itr)
|
self._services_model.remove(s_itr)
|
||||||
|
if index % self.DEL_FACTOR == 0:
|
||||||
|
yield True
|
||||||
|
|
||||||
srv_ids_to_delete = set()
|
srv_ids_to_delete = set()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@@ -649,8 +661,10 @@ class Application(Gtk.Application):
|
|||||||
|
|
||||||
for f_itr in filter(lambda r: r[Column.FAV_ID] in srv_ids_to_delete, self._fav_model):
|
for f_itr in filter(lambda r: r[Column.FAV_ID] in srv_ids_to_delete, self._fav_model):
|
||||||
self._fav_model.remove(f_itr.iter)
|
self._fav_model.remove(f_itr.iter)
|
||||||
|
|
||||||
self.update_fav_num_column(self._fav_model)
|
self.update_fav_num_column(self._fav_model)
|
||||||
self.update_sat_positions()
|
self.update_sat_positions()
|
||||||
|
self._wait_dialog.hide()
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
def delete_bouquets(self, itrs, model):
|
def delete_bouquets(self, itrs, model):
|
||||||
@@ -668,6 +682,9 @@ class Application(Gtk.Application):
|
|||||||
self._bouquets.pop("{}:{}".format(b_row[Column.BQ_NAME], b_row[Column.BQ_TYPE]), None)
|
self._bouquets.pop("{}:{}".format(b_row[Column.BQ_NAME], b_row[Column.BQ_TYPE]), None)
|
||||||
self._bouquets_model.remove(itr)
|
self._bouquets_model.remove(itr)
|
||||||
|
|
||||||
|
self._wait_dialog.hide()
|
||||||
|
yield True
|
||||||
|
|
||||||
# ***************** ####### *********************#
|
# ***************** ####### *********************#
|
||||||
|
|
||||||
def get_bouquet_file_name(self, bouquet):
|
def get_bouquet_file_name(self, bouquet):
|
||||||
@@ -1032,7 +1049,7 @@ class Application(Gtk.Application):
|
|||||||
def open_data(self, data_path=None, callback=None):
|
def open_data(self, data_path=None, callback=None):
|
||||||
""" Opening data and fill views. """
|
""" Opening data and fill views. """
|
||||||
gen = self.update_data(data_path, callback)
|
gen = self.update_data(data_path, callback)
|
||||||
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_DEFAULT_IDLE)
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
||||||
|
|
||||||
def update_data(self, data_path, callback=None):
|
def update_data(self, data_path, callback=None):
|
||||||
self._profile_combo_box.set_sensitive(False)
|
self._profile_combo_box.set_sensitive(False)
|
||||||
@@ -1160,11 +1177,12 @@ class Application(Gtk.Application):
|
|||||||
|
|
||||||
def append_services(self, services):
|
def append_services(self, services):
|
||||||
for srv in services:
|
for srv in services:
|
||||||
# adding channels to dict with fav_id as keys
|
# Adding channels to dict with fav_id as keys.
|
||||||
self._services[srv.fav_id] = srv
|
self._services[srv.fav_id] = srv
|
||||||
self.update_services_counts(len(self._services.values()))
|
self.update_services_counts(len(self._services.values()))
|
||||||
|
factor = self.DEL_FACTOR * 2
|
||||||
|
|
||||||
for srv in services:
|
for index, srv in enumerate(services):
|
||||||
tooltip, background = None, None
|
tooltip, background = None, None
|
||||||
if self._use_colors:
|
if self._use_colors:
|
||||||
flags = srv.flags_cas
|
flags = srv.flags_cas
|
||||||
@@ -1173,13 +1191,17 @@ class Application(Gtk.Application):
|
|||||||
if f_flags and Flag.is_new(int(f_flags[0][2:])):
|
if f_flags and Flag.is_new(int(f_flags[0][2:])):
|
||||||
background = self._NEW_COLOR
|
background = self._NEW_COLOR
|
||||||
|
|
||||||
s = srv + (tooltip, background)
|
s = srv._replace(picon=self._picons.get(srv.picon_id, None)) + (tooltip, background)
|
||||||
itr = self._services_model.append(s)
|
self._services_model.append(s)
|
||||||
self._services_model.set_value(itr, Column.SRV_PICON, self._picons.get(srv.picon_id, None))
|
if index % factor == 0:
|
||||||
yield True
|
yield True
|
||||||
|
yield True
|
||||||
|
|
||||||
def clear_current_data(self):
|
def clear_current_data(self):
|
||||||
""" Clearing current data from lists """
|
""" Clearing current data from lists """
|
||||||
|
if len(self._services_model) > self.DEL_FACTOR * 100:
|
||||||
|
self._wait_dialog.set_text("Deleting data...")
|
||||||
|
|
||||||
self._bouquets_model.clear()
|
self._bouquets_model.clear()
|
||||||
yield True
|
yield True
|
||||||
self._fav_model.clear()
|
self._fav_model.clear()
|
||||||
@@ -1189,7 +1211,7 @@ class Application(Gtk.Application):
|
|||||||
yield True
|
yield True
|
||||||
for index, itr in enumerate([row.iter for row in self._services_model]):
|
for index, itr in enumerate([row.iter for row in self._services_model]):
|
||||||
self._services_model.remove(itr)
|
self._services_model.remove(itr)
|
||||||
if index % 25 == 0:
|
if index % self.DEL_FACTOR == 0:
|
||||||
yield True
|
yield True
|
||||||
yield True
|
yield True
|
||||||
self._services_view.set_model(s_model)
|
self._services_view.set_model(s_model)
|
||||||
@@ -1203,6 +1225,7 @@ class Application(Gtk.Application):
|
|||||||
self._bq_name_label.set_text("")
|
self._bq_name_label.set_text("")
|
||||||
self.init_sat_positions()
|
self.init_sat_positions()
|
||||||
self.update_services_counts()
|
self.update_services_counts()
|
||||||
|
self._wait_dialog.set_text(None)
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
def on_data_save(self, *args):
|
def on_data_save(self, *args):
|
||||||
@@ -1307,7 +1330,6 @@ class Application(Gtk.Application):
|
|||||||
def on_bouquets_selection(self, model, path, column):
|
def on_bouquets_selection(self, model, path, column):
|
||||||
self._current_bq_name = model[path][0] if len(path) > 1 else None
|
self._current_bq_name = model[path][0] if len(path) > 1 else None
|
||||||
self._bq_name_label.set_text(self._current_bq_name if self._current_bq_name else "")
|
self._bq_name_label.set_text(self._current_bq_name if self._current_bq_name else "")
|
||||||
self._fav_model.clear()
|
|
||||||
|
|
||||||
if self._current_bq_name:
|
if self._current_bq_name:
|
||||||
ch_row = model[model.get_iter(path)][:]
|
ch_row = model[model.get_iter(path)][:]
|
||||||
@@ -1321,9 +1343,8 @@ class Application(Gtk.Application):
|
|||||||
self._bouquets_view.expand_row(path, column)
|
self._bouquets_view.expand_row(path, column)
|
||||||
|
|
||||||
if len(path) > 1:
|
if len(path) > 1:
|
||||||
next(self.update_bouquet_services(model, path), False)
|
gen = self.update_bouquet_services(model, path)
|
||||||
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
||||||
self.on_view_focus(self._bouquets_view)
|
|
||||||
|
|
||||||
def update_bouquet_services(self, model, path, bq_key=None):
|
def update_bouquet_services(self, model, path, bq_key=None):
|
||||||
""" Updates list of bouquet services """
|
""" Updates list of bouquet services """
|
||||||
@@ -1332,10 +1353,15 @@ class Application(Gtk.Application):
|
|||||||
tree_iter = model.get_iter(path)
|
tree_iter = model.get_iter(path)
|
||||||
|
|
||||||
key = bq_key if bq_key else "{}:{}".format(*model.get(tree_iter, Column.BQ_NAME, Column.BQ_TYPE))
|
key = bq_key if bq_key else "{}:{}".format(*model.get(tree_iter, Column.BQ_NAME, Column.BQ_TYPE))
|
||||||
services = self._bouquets.get(key, None)
|
services = self._bouquets.get(key, [])
|
||||||
ex_services = self._extra_bouquets.get(key, None)
|
ex_services = self._extra_bouquets.get(key, None)
|
||||||
if not services:
|
|
||||||
return
|
factor = self.FAV_FACTOR * 5
|
||||||
|
if len(services) > factor or len(self._fav_model) > factor:
|
||||||
|
GLib.idle_add(self._bouquets_view.set_sensitive, False)
|
||||||
|
|
||||||
|
self._fav_model.clear()
|
||||||
|
yield True
|
||||||
|
|
||||||
for num, srv_id in enumerate(services):
|
for num, srv_id in enumerate(services):
|
||||||
srv = self._services.get(srv_id, None)
|
srv = self._services.get(srv_id, None)
|
||||||
@@ -1347,6 +1373,11 @@ class Application(Gtk.Application):
|
|||||||
self._fav_model.append((num + 1, srv.coded, ex_srv_name if ex_srv_name else srv.service, srv.locked,
|
self._fav_model.append((num + 1, srv.coded, ex_srv_name if ex_srv_name else srv.service, srv.locked,
|
||||||
srv.hide, srv.service_type, srv.pos, srv.fav_id,
|
srv.hide, srv.service_type, srv.pos, srv.fav_id,
|
||||||
self._picons.get(srv.picon_id, None), None, background))
|
self._picons.get(srv.picon_id, None), None, background))
|
||||||
|
if num % self.FAV_FACTOR == 0:
|
||||||
|
yield True
|
||||||
|
|
||||||
|
GLib.idle_add(self._bouquets_view.set_sensitive, True)
|
||||||
|
GLib.idle_add(self._bouquets_view.grab_focus)
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
def check_bouquet_selection(self):
|
def check_bouquet_selection(self):
|
||||||
@@ -1701,7 +1732,9 @@ class Application(Gtk.Application):
|
|||||||
for srv in services:
|
for srv in services:
|
||||||
self._services[srv.fav_id] = srv
|
self._services[srv.fav_id] = srv
|
||||||
bq_services.append(srv.fav_id)
|
bq_services.append(srv.fav_id)
|
||||||
next(self.update_bouquet_services(self._fav_model, None, self._bq_selected), False)
|
|
||||||
|
gen = self.update_bouquet_services(self._fav_model, None, self._bq_selected)
|
||||||
|
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
|
||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
def on_export_to_m3u(self, action, value=None):
|
def on_export_to_m3u(self, action, value=None):
|
||||||
|
|||||||
@@ -144,10 +144,11 @@ class PiconsDialog:
|
|||||||
p_model = self._picons_view.get_model()
|
p_model = self._picons_view.get_model()
|
||||||
model = get_base_model(p_model)
|
model = get_base_model(p_model)
|
||||||
self._picons_view.set_model(None)
|
self._picons_view.set_model(None)
|
||||||
|
factor = self._app.DEL_FACTOR
|
||||||
|
|
||||||
for index, itr in enumerate([row.iter for row in model]):
|
for index, itr in enumerate([row.iter for row in model]):
|
||||||
model.remove(itr)
|
model.remove(itr)
|
||||||
if index % 50 == 0:
|
if index % factor == 0:
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
for file in os.listdir(path):
|
for file in os.listdir(path):
|
||||||
|
|||||||
Reference in New Issue
Block a user