Dev: New Node performance in sqlite backend

Home Forums cherrytree Dev: New Node performance in sqlite backend

This topic contains 0 replies, has 1 voice, and was last updated by  acry 1 month ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #125005

    acry
    Member

    Hi Giuseppe and hello folks!

    Sorry this is my first entry and I keep failing, after editing my post is lost.

    I am using CT for quite a bit now, my biggest notebook has more than 3k nodes.
    If I add a node it takes about 8 seconds even so I use the sqlite backend.

    In core’s node_id_get() you are iterating through all nodes which takes
    its time. I tried to fix that issue for me.

    I don’t know the smartest way to know which backend the current db uses.
    And don’t think the best place of an db_is_sqlite var is core, probably
    the ctdb module on get_connected_db_from_dbpath() ?

    The outline of the changes look like that:

    core.py
    self.db_is_sqlite = False

    def node_id_get
                new_node_id = 1
                if self.db_is_sqlite:
                    new_node_id += self.ctdb_handler.get_last_node_id(self.db)
                else:
                    while (self.get_tree_iter_from_node_id(new_node_id)):
                        new_node_id += 1
                while (new_node_id in self.ctdb_handler.nodes_to_rm_set) or (new_node_id in discard_ids_allocated):
                    new_node_id += 1
                if discard_ids is not None:
                    discard_ids[original_id] = new_node_id
            return new_node_id
    def file_save_as
            if self.filetype in ["b", "x"]:
                self.db_is_sqlite = True
            else:
                self.db_is_sqlite = False
    def file_load
    	if self.filetype in ["d", "z"]:
    	# xml
    	if self.xml_handler.dom_to_treestore(cherrytree_string, discard_ids=None):
    		document_loaded_ok = True
    		self.db_is_sqlite = False
    	else:
    	# db
    	self.ctdb_handler.read_db_full(self.db, discard_ids=None)
    	document_loaded_ok = True
    	self.db_is_sqlite = True

    ctdb.py

    def get_last_node_id(self, db):
            """Returns the last node_id from table node"""
            cursor = db.execute('SELECT max(node_id) FROM node')
            max_id = cursor.fetchone()[0]
            return max_id

    Is this safe or will I corrupt my db?

    I am willed to produce a git patch if my suggestion is applicable.

    Cheers,
    Carsten

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.