]> git.phdru.name Git - m_librarian.git/commitdiff
Speedup inp import by caching a set of files in the archive
authorOleg Broytman <phd@phdru.name>
Sun, 6 Mar 2016 13:43:07 +0000 (16:43 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 6 Mar 2016 15:07:55 +0000 (18:07 +0300)
m_librarian/db.py
m_librarian/inp.py

index 65c79873612025d57bbda38955b8dc97787c0b6b..99a2843aa42f3ad5f347a86efaecde0b30b6a1d5 100755 (executable)
@@ -95,6 +95,7 @@ class Book(SQLObject):
     title_idx = DatabaseIndex(title)
     series_idx = DatabaseIndex(series)
     ser_no_idx = DatabaseIndex(ser_no)
+    archive_idx = DatabaseIndex(archive)
     archive_file_idx = DatabaseIndex(archive, file, unique=True)
     file_idx = DatabaseIndex(file)
     size_idx = DatabaseIndex(size)
index 09cd42be2151a5e7b11dda19673cbada15578721..dd32c0825494f45d58c5029288a312a1df6b3b8a 100644 (file)
@@ -3,7 +3,8 @@ __all__ = ['import_inpx']
 
 import os
 from zipfile import ZipFile
-from sqlobject import sqlhub, SQLObjectNotFound
+from sqlobject import sqlhub
+from sqlobject.sqlbuilder import Select
 from .db import Author, Book, Extension, Genre, Language, \
     insert_name, insert_author
 
@@ -26,12 +27,6 @@ def split_line(line):
 def import_inp_line(archive, parts):
     authors, genres, title, series, ser_no, file, size, lib_id, deleted, \
         extension, date, language = parts
-    try:
-        Book.archive_file_idx.get(archive, file)
-    except SQLObjectNotFound:
-        pass
-    else:
-        return
     try:
         ser_no = int(ser_no)
     except ValueError:
@@ -71,8 +66,17 @@ def import_inp_line(archive, parts):
 
 
 def import_inp(archive, inp):
+    files = set()
+    connection = sqlhub.processConnection
+    for file, in connection.queryAll(connection.sqlrepr(
+            Select(Book.q.file, Book.q.archive == archive))):
+        files.add(file)
     for line in inp:
-        import_inp_line(archive, split_line(line))
+        parts = split_line(line)
+        file = parts[5]
+        if file not in files:
+            files.add(file)
+            import_inp_line(archive, parts)
 
 
 def import_inpx(path):