1. Iñigo Serna
  2. bidebarrieta

Commits

Iñigo Serna  committed 2335ef8

BulkEdit: commit at end, not once per ebook => much faster

  • Participants
  • Parent commits e58b5ef
  • Branches default

Comments (0)

Files changed (4)

File TODO

View file
 ============================================================================
-Last update:	Time-stamp: <2012-05-28 14:55:27 inigo>
+Last update:	Time-stamp: <2012-05-28 18:45:04 inigo>
 ============================================================================
 
 
 . fix bug: crash at libs check if library name with non-ascii chars
 . fix bug: add ebooks, switch lib => default covers are shown, not ebook
 . create a new model each time a lib is loaded => switching libs is much faster
+. bulkedit: commit at end, not once per ebook => much faster
 
 
 v0.6

File db.py

View file
 
 
 def add_folder_parameters(path, recursive, pattern):
-    cur.execute('INSERT INTO folders VALUES (?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)', (path, recursive, pattern))
+    now = datetime.datetime.now()
+    cur.execute('INSERT INTO folders VALUES (?, ?, ?, ?, ?)', (path, recursive, pattern, now, now))
     conn.commit()
 
 
 def update_folder_update(path):
-    cur.execute('UPDATE folders SET lastupdate=CURRENT_TIMESTAMP WHERE path=?', (path, ))
+    now = datetime.datetime.now()
+    cur.execute('UPDATE folders SET lastupdate=? WHERE path=?', (now, path))
     conn.commit()
 
 
                   (self.title, ', '.join([a.name for a in self.authors]), self.id, in_db)
         return buf.encode('UTF-8')
 
-    def update_field(self, col, val):
+    def update_field(self, col, val, delay_commit=False):
         if col in ('title', 'pubdate', 'edition', 'isbn', 'lang', 'rating', 'comments'):
             setattr(self, col, val)
             cur.execute('UPDATE books SET %s=? WHERE book_id=?' % col, (val, self.id))
                 cur.execute('INSERT INTO books_tags VALUES (?, ?)', (self.id, tag.id))
         self.modified = datetime.datetime.now()
         cur.execute('UPDATE books SET modified=? WHERE book_id=?', (self.modified, self.id))
-        lib_commit()
+        if not delay_commit:
+            lib_commit()
 
     def to_dict(self, datefmt=DEFAULT_DATEFMT):
         bookdict = {}

File ui/bulk_edit.py

View file
         cr.set_property('ellipsize', pango.ELLIPSIZE_START)
         col = gtk.TreeViewColumn(' Path ', cr, text=1)
         self.view.append_column(col)
-        self.model = gtk.ListStore(long, str, object)
-        self.view.set_model(self.model)
+        self.model = None
 
         # right: table and buttons
         vbox = gtk.VBox(False, 10)
         model, paths = self.view.get_selection().get_selected_rows()
         if model is None or len(paths) == 0:
             return False
+        self.app.listview.freeze_child_notify()
+        self.app.prettyview.freeze_child_notify()
+        self.app.iconview.freeze_child_notify()
         for book_id, path in [(model[path][0], path) for path in paths]:
             book = db.Book().get_by_id(book_id)
             if ctitle != 0 and title != DIFFSTR:
-                book.update_field('title', unicode(title))
+                book.update_field('title', unicode(title), delay_commit=True)
             if crating != 0 and rating != -1:
-                book.update_field('rating', rating)
+                book.update_field('rating', rating, delay_commit=True)
             if cauthors != 0 and authors != DIFFSTR:
                 authors2 = [a.strip() for a in authors.split('&') if a.strip() != '']
-                book.update_field('author', authors2)
+                book.update_field('author', authors2, delay_commit=True)
             if cauthors_sort != 0 and authors_sort != DIFFSTR:
                 authors_sort2 = [a.strip() for a in authors_sort.split('&')]
-                book.update_field('author_sort', authors_sort2)
+                book.update_field('author_sort', authors_sort2, delay_commit=True)
             if cpublisher != 0 and publisher != DIFFSTR:
-                book.update_field('publisher', unicode(publisher))
+                book.update_field('publisher', unicode(publisher), delay_commit=True)
             if cpubdate != 0 and pubdate != DIFFSTR:
-                book.update_field('pubdate', get_pubdate(pubdate))
+                book.update_field('pubdate', get_pubdate(pubdate), delay_commit=True)
             if cedition != 0 and edition != DIFFSTR:
-                book.update_field('edition', get_edition(edition))
+                book.update_field('edition', get_edition(edition), delay_commit=True)
             if cisbn != 0 and isbn != DIFFSTR:
-                book.update_field('isbn', isbn)
+                book.update_field('isbn', isbn, delay_commit=True)
             if clang != 0 and lang != DIFFSTR:
-                book.update_field('lang', lang)
+                book.update_field('lang', lang, delay_commit=True)
             if ctags != 0 and tags != DIFFSTR:
                 tags2 = [t.strip() for t in tags.split(',') if t.strip() != '']
-                book.update_field('tags', tags2)
+                book.update_field('tags', tags2, delay_commit=True)
             self.app.model_update_row(book)
             model[path][2] = book # update bulk_edit model
+        db.lib_commit()
         self.update_contents(paths)
         self.app.bookinfo.update_contents()
         self.app.viewedit.update_contents()
+        self.app.listview.thaw_child_notify()
+        self.app.prettyview.thaw_child_notify()
+        self.app.iconview.thaw_child_notify()
         return True
 
 
 
     def on(self, books_id, libpath):
         self.books_id = books_id
-        self.model.clear()
+        self.view.set_model(None)
+        if self.model is not None:
+            self.model.clear()
+            del self.model
+        self.model = gtk.ListStore(long, str, object)
         for book_id in books_id:
             book = db.Book().get_by_id(book_id)
             self.model.append([book_id, book.path, book])
+        self.view.set_model(self.model)
         self.view.get_selection().select_all() # update contents automatically
         self.set_default_size(*self.size)
         self.move(*self.pos)

File ui/view_edit.py

View file
             return False
         # and now store the changes
         book = db.Book().get_by_id(self.app.last_book_id)
-        book.update_field('title', unicode(title))
-        book.update_field('rating', rating)
+        book.update_field('title', unicode(title), delay_commit=True)
+        book.update_field('rating', rating, delay_commit=True)
         if authors != '' and (authors_sort == '' or self.cmbentry_authorsort.check_value() == 0):
             authors = [a.strip() for a in authors.split('&') if a.strip() != '']
-            book.update_field('author', authors)
+            book.update_field('author', authors, delay_commit=True)
         else:
             authors_sort = [a.strip() for a in authors_sort.split('&')]
-            book.update_field('author_sort', authors_sort)
-        book.update_field('publisher', unicode(publisher))
+            book.update_field('author_sort', authors_sort, delay_commit=True)
+        book.update_field('publisher', unicode(publisher), delay_commit=True)
         pubdate = get_pubdate(pubdate)
-        book.update_field('pubdate', pubdate)
+        book.update_field('pubdate', pubdate, delay_commit=True)
         edition = get_edition(edition)
-        book.update_field('edition', edition)
-        book.update_field('isbn', isbn)
-        book.update_field('lang', lang)
-        book.update_field('comments', comments)
+        book.update_field('edition', edition, delay_commit=True)
+        book.update_field('isbn', isbn, delay_commit=True)
+        book.update_field('lang', lang, delay_commit=True)
+        book.update_field('comments', comments, delay_commit=True)
         tags = [t.strip() for t in tags.split(',') if t.strip() != '']
-        book.update_field('tags', tags)
+        book.update_field('tags', tags, delay_commit=True)
+        db.lib_commit()
         # TODO: cover
         self.app.model_update_row(book)
         self.app.bookinfo.update_contents()