Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
29b94c56
Commit
29b94c56
authored
May 19, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #1407 (to many read books lead to to large sql query) -> only fix for linked calibre-column
parent
4332f7a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
18 deletions
+23
-18
helper.py
cps/helper.py
+5
-5
web.py
cps/web.py
+18
-13
No files found.
cps/helper.py
View file @
29b94c56
...
@@ -824,12 +824,12 @@ def fill_indexpage_with_archived_books(page, database, db_filter, order, allow_s
...
@@ -824,12 +824,12 @@ def fill_indexpage_with_archived_books(page, database, db_filter, order, allow_s
else
:
else
:
randm
=
false
()
randm
=
false
()
off
=
int
(
int
(
config
.
config_books_per_page
)
*
(
page
-
1
))
off
=
int
(
int
(
config
.
config_books_per_page
)
*
(
page
-
1
))
query
=
db
.
session
.
query
(
database
)
.
join
(
*
join
,
isouter
=
True
)
.
\
filter
(
db_filter
)
.
\
filter
(
common_filters
(
allow_show_archived
))
pagination
=
Pagination
(
page
,
config
.
config_books_per_page
,
pagination
=
Pagination
(
page
,
config
.
config_books_per_page
,
len
(
db
.
session
.
query
(
database
)
.
filter
(
db_filter
)
len
(
query
.
all
()))
.
filter
(
common_filters
(
allow_show_archived
))
.
all
()))
entries
=
query
.
order_by
(
*
order
)
.
offset
(
off
)
.
limit
(
config
.
config_books_per_page
)
.
all
()
entries
=
db
.
session
.
query
(
database
)
.
join
(
*
join
,
isouter
=
True
)
.
filter
(
db_filter
)
\
.
filter
(
common_filters
(
allow_show_archived
))
\
.
order_by
(
*
order
)
.
offset
(
off
)
.
limit
(
config
.
config_books_per_page
)
.
all
()
for
book
in
entries
:
for
book
in
entries
:
book
=
order_authors
(
book
)
book
=
order_authors
(
book
)
return
entries
,
randm
,
pagination
return
entries
,
randm
,
pagination
...
...
cps/web.py
View file @
29b94c56
...
@@ -40,6 +40,7 @@ from flask_login import login_user, logout_user, login_required, current_user
...
@@ -40,6 +40,7 @@ from flask_login import login_user, logout_user, login_required, current_user
from
sqlalchemy.exc
import
IntegrityError
from
sqlalchemy.exc
import
IntegrityError
from
sqlalchemy.sql.expression
import
text
,
func
,
true
,
false
,
not_
,
and_
,
or_
from
sqlalchemy.sql.expression
import
text
,
func
,
true
,
false
,
not_
,
and_
,
or_
from
werkzeug.exceptions
import
default_exceptions
from
werkzeug.exceptions
import
default_exceptions
from
sqlalchemy.sql.functions
import
coalesce
try
:
try
:
from
werkzeug.exceptions
import
FailedDependency
from
werkzeug.exceptions
import
FailedDependency
except
ImportError
:
except
ImportError
:
...
@@ -1102,31 +1103,35 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs)
...
@@ -1102,31 +1103,35 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs)
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
\
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
\
.
filter
(
ub
.
ReadBook
.
read_status
==
ub
.
ReadBook
.
STATUS_FINISHED
)
.
all
()
.
filter
(
ub
.
ReadBook
.
read_status
==
ub
.
ReadBook
.
STATUS_FINISHED
)
.
all
()
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
if
are_read
:
db_filter
=
db
.
Books
.
id
.
in_
(
readBookIds
)
else
:
db_filter
=
~
db
.
Books
.
id
.
in_
(
readBookIds
)
entries
,
random
,
pagination
=
fill_indexpage
(
page
,
db
.
Books
,
db_filter
,
order
)
else
:
else
:
try
:
try
:
readBooks
=
db
.
session
.
query
(
db
.
cc_classes
[
config
.
config_read_column
])
\
if
are_read
:
.
filter
(
db
.
cc_classes
[
config
.
config_read_column
]
.
value
==
True
)
.
all
()
db_filter
=
db
.
cc_classes
[
config
.
config_read_column
]
.
value
==
True
readBookIds
=
[
x
.
book
for
x
in
readBooks
]
else
:
db_filter
=
coalesce
(
db
.
cc_classes
[
config
.
config_read_column
]
.
value
,
False
)
!=
True
# book_count = db.session.query(func.count(db.Books.id)).filter(common_filters()).filter(db_filter).scalar()
entries
,
random
,
pagination
=
fill_indexpage
(
page
,
db
.
Books
,
db_filter
,
order
,
db
.
cc_classes
[
config
.
config_read_column
])
except
KeyError
:
except
KeyError
:
log
.
error
(
"Custom Column No.
%
d is not existing in calibre database"
,
config
.
config_read_column
)
log
.
error
(
"Custom Column No.
%
d is not existing in calibre database"
,
config
.
config_read_column
)
readBookIds
=
[]
book_count
=
0
if
are_read
:
db_filter
=
db
.
Books
.
id
.
in_
(
readBookIds
)
else
:
db_filter
=
~
db
.
Books
.
id
.
in_
(
readBookIds
)
entries
,
random
,
pagination
=
fill_indexpage
(
page
,
db
.
Books
,
db_filter
,
order
)
if
as_xml
:
if
as_xml
:
return
entries
,
pagination
return
entries
,
pagination
else
:
else
:
if
are_read
:
if
are_read
:
name
=
_
(
u'Read Books'
)
+
' ('
+
str
(
len
(
readBookIds
)
)
+
')'
name
=
_
(
u'Read Books'
)
+
' ('
+
str
(
pagination
.
total_count
)
+
')'
pagename
=
"read"
pagename
=
"read"
else
:
else
:
total_books
=
db
.
session
.
query
(
func
.
count
(
db
.
Books
.
id
))
.
filter
(
common_filters
())
.
scalar
()
name
=
_
(
u'Unread Books'
)
+
' ('
+
str
(
pagination
.
total_count
)
+
')'
name
=
_
(
u'Unread Books'
)
+
' ('
+
str
(
total_books
-
len
(
readBookIds
))
+
')'
pagename
=
"unread"
pagename
=
"unread"
return
render_title_template
(
'index.html'
,
random
=
random
,
entries
=
entries
,
pagination
=
pagination
,
return
render_title_template
(
'index.html'
,
random
=
random
,
entries
=
entries
,
pagination
=
pagination
,
title
=
name
,
page
=
pagename
)
title
=
name
,
page
=
pagename
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment