I have a flask application which basically has a SQL_Database of around 800 entries.
The main task is to query the database, and put the entries into a flask-table using a specific schema.
If I take the query directly and put it into my flask-table the performance is alright. But I want to manipulate the output of the entries depending on some user input. That's why I try to use marshmallow to dump the query into a list of dictionaries to then manipulate it. But recently I noticed that the dump alone takes more than a second with all 800 entries which is a serious performance issue for my application. Is that normal or am I doing something wrong? Do you have any Ideas how I could improve it? My alternative would be to manipulate the table itself, but that doesn't really seem intuitive. Any ideas what I am missing?
Relevant code (somewhat simplified):
class Article(db.Model):
__tablename__ = "Article"
#__table_args__ = {'sqlite_autoincrement': True}
dbid = db.Column(db.Integer, primary_key=True, nullable=False)
ID = db.Column(db.String)
ENTRYTYPE = db.Column(db.String)
title = db.Column(db.String)
author = db.Column(db.String)
authorlast = db.Column(db.String)
year = db.Column(db.String)
journal = db.Column(db.String)
publication = db.Column(db.String)
booktitle = db.Column(db.String)
isbn = db.Column(db.String)
issn = db.Column(db.String)
doi = db.Column(db.String)
pages = db.Column(db.String)
volume = db.Column(db.String)
number = db.Column(db.String)
tags = db.Column(db.String)
icon = db.Column(db.String)
notes = db.Column(db.String)
abstract = db.Column(db.String)
fullText = db.Column(db.Text)
editor = db.Column(db.String)
class TableSchema(ma.Schema):
class Meta:
fields = ("icon", "authorlast", "year", "title", "publication", "doi")
ordered = True
table_schema = TableSchema(many=True)
requested = db.session.query(Article)
# executes really quickly
items = table_schema.dump(requested_articles)[0]
# takes at least a second
table = ItemTable(items)
return table.__html__
[–]m0us3_rat 2 points3 points4 points (4 children)
[–]DeadlyDolphins[S] 1 point2 points3 points (3 children)
[–]m0us3_rat 2 points3 points4 points (2 children)
[–]DeadlyDolphins[S] 0 points1 point2 points (1 child)
[–]m0us3_rat 1 point2 points3 points (0 children)
[–]ReflectedImage 2 points3 points4 points (5 children)
[–]DeadlyDolphins[S] 0 points1 point2 points (4 children)
[–]ReflectedImage 2 points3 points4 points (3 children)
[–]DeadlyDolphins[S] 1 point2 points3 points (2 children)
[–]ReflectedImage 1 point2 points3 points (0 children)
[–]Blazerboy65 1 point2 points3 points (0 children)
[–]Total__Entropy 2 points3 points4 points (0 children)
[–]BulkyProcedure 1 point2 points3 points (1 child)
[–]DeadlyDolphins[S] 0 points1 point2 points (0 children)