Change to reduce impact of the tweak to only the DB

This commit is contained in:
Charles Haley 2010-06-10 21:29:37 +01:00
parent fe1316f201
commit 1411f34b15
3 changed files with 20 additions and 11 deletions

View File

@ -12,7 +12,6 @@ from urlparse import urlparse
from calibre import relpath, prints from calibre import relpath, prints
from calibre.utils.config import tweaks
from calibre.utils.date import isoformat from calibre.utils.date import isoformat
_author_pat = re.compile(',?\s+(and|with)\s+', re.IGNORECASE) _author_pat = re.compile(',?\s+(and|with)\s+', re.IGNORECASE)
@ -43,11 +42,10 @@ def authors_to_sort_string(authors):
_title_pat = re.compile('^(A|The|An)\s+', re.IGNORECASE) _title_pat = re.compile('^(A|The|An)\s+', re.IGNORECASE)
def title_sort(title): def title_sort(title):
if tweaks['title_sorting'] == 'library_order': match = _title_pat.search(title)
match = _title_pat.search(title) if match:
if match: prep = match.group(1)
prep = match.group(1) title = title[len(prep):] + ', ' + prep
title = title[len(prep):] + ', ' + prep
return title.strip() return title.strip()
coding = zip( coding = zip(

View File

@ -28,7 +28,7 @@ from calibre.customize.ui import run_plugins_on_import
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.utils.date import utcnow, now as nowf, utcfromtimestamp from calibre.utils.date import utcnow, now as nowf, utcfromtimestamp
from calibre.utils.config import prefs from calibre.utils.config import prefs, tweaks
from calibre.utils.search_query_parser import saved_searches from calibre.utils.search_query_parser import saved_searches
from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
from calibre.utils.magick_draw import save_cover_data_to from calibre.utils.magick_draw import save_cover_data_to
@ -736,8 +736,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
icon=icon, tooltip = tooltip) icon=icon, tooltip = tooltip)
for r in data if item_not_zero_func(r)] for r in data if item_not_zero_func(r)]
if category == 'series' and not sort_on_count: if category == 'series' and not sort_on_count:
categories[category].sort(cmp=lambda x,y:cmp(title_sort(x.name).lower(), if tweaks['title_sorting'] == 'library_order':
title_sort(y.name).lower())) ts = lambda x: title_sort(x)
else:
ts = lambda x:x
categories[category].sort(cmp=lambda x,y:cmp(ts(x.name).lower(),
ts(y.name).lower()))
# We delayed computing the standard formats category because it does not # We delayed computing the standard formats category because it does not
# use a view, but is computed dynamically # use a view, but is computed dynamically
@ -950,7 +954,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
title = title.decode(preferred_encoding, 'replace') title = title.decode(preferred_encoding, 'replace')
self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id)) self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id))
self.data.set(id, self.FIELD_MAP['title'], title, row_is_id=True) self.data.set(id, self.FIELD_MAP['title'], title, row_is_id=True)
self.data.set(id, self.FIELD_MAP['sort'], title_sort(title), row_is_id=True) if tweaks['title_sorting'] == 'library_order':
self.data.set(id, self.FIELD_MAP['sort'], title_sort(title), row_is_id=True)
else:
self.data.set(id, self.FIELD_MAP['sort'], title, row_is_id=True)
self.set_path(id, True) self.set_path(id, True)
self.conn.commit() self.conn.commit()
if notify: if notify:

View File

@ -15,6 +15,7 @@ from threading import RLock
from datetime import datetime from datetime import datetime
from calibre.ebooks.metadata import title_sort from calibre.ebooks.metadata import title_sort
from calibre.utils.config import tweaks
from calibre.utils.date import parse_date, isoformat from calibre.utils.date import parse_date, isoformat
global_lock = RLock() global_lock = RLock()
@ -115,7 +116,10 @@ class DBThread(Thread):
self.conn.create_aggregate('concat', 1, Concatenate) self.conn.create_aggregate('concat', 1, Concatenate)
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate) self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate) self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
self.conn.create_function('title_sort', 1, title_sort) if tweaks['title_sorting'] == 'library_order':
self.conn.create_function('title_sort', 1, title_sort)
else:
self.conn.create_function('title_sort', 1, lambda x:x)
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4())) self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
# Dummy functions for dynamically created filters # Dummy functions for dynamically created filters
self.conn.create_function('books_list_filter', 1, lambda x: 1) self.conn.create_function('books_list_filter', 1, lambda x: 1)