Commit 516734c9 authored by Konstantin Schulz's avatar Konstantin Schulz

commit after (almost) every database access to avoid "idle in transaction"...

commit after (almost) every database access to avoid "idle in transaction" state of the database connections/sessions
parent d0e48807
Pipeline #11599 failed with stages
in 2 minutes and 54 seconds
...@@ -21,5 +21,6 @@ def get(last_update_time: int) -> Union[Response, ConnexionResponse]: ...@@ -21,5 +21,6 @@ def get(last_update_time: int) -> Union[Response, ConnexionResponse]:
return NetworkService.make_json_response(None) return NetworkService.make_json_response(None)
if ui_cts.last_modified_time >= last_update_time / 1000: if ui_cts.last_modified_time >= last_update_time / 1000:
corpora: List[Corpus] = db.session.query(Corpus).all() corpora: List[Corpus] = db.session.query(Corpus).all()
db.session.commit()
return NetworkService.make_json_response([x.to_dict() for x in corpora]) return NetworkService.make_json_response([x.to_dict() for x in corpora])
return NetworkService.make_json_response(None) return NetworkService.make_json_response(None)
...@@ -27,6 +27,7 @@ def adjust_solutions(exercise_data: ExerciseData, exercise_type: str, solutions: ...@@ -27,6 +27,7 @@ def adjust_solutions(exercise_data: ExerciseData, exercise_type: str, solutions:
def get(eid: str) -> Union[Response, ConnexionResponse]: def get(eid: str) -> Union[Response, ConnexionResponse]:
exercise: TExercise = db.session.query(Exercise).filter_by(eid=eid).first() exercise: TExercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
if exercise is None: if exercise is None:
return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND, Config.ERROR_MESSAGE_EXERCISE_NOT_FOUND) return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND, Config.ERROR_MESSAGE_EXERCISE_NOT_FOUND)
ar: AnnisResponse = CorpusService.get_corpus(cts_urn=exercise.urn, is_csm=False) ar: AnnisResponse = CorpusService.get_corpus(cts_urn=exercise.urn, is_csm=False)
......
...@@ -34,6 +34,7 @@ class ExerciseListAPI(Resource): ...@@ -34,6 +34,7 @@ class ExerciseListAPI(Resource):
last_update: int = args["last_update_time"] last_update: int = args["last_update_time"]
ui_exercises: UpdateInfo = db.session.query(UpdateInfo).filter_by( ui_exercises: UpdateInfo = db.session.query(UpdateInfo).filter_by(
resource_type=ResourceType.exercise_list.name).first() resource_type=ResourceType.exercise_list.name).first()
db.session.commit()
if ui_exercises.last_modified_time < last_update / 1000: if ui_exercises.last_modified_time < last_update / 1000:
return NetworkService.make_json_response([]) return NetworkService.make_json_response([])
try: try:
...@@ -47,6 +48,7 @@ class ExerciseListAPI(Resource): ...@@ -47,6 +48,7 @@ class ExerciseListAPI(Resource):
except ValueError: except ValueError:
lang = Language.English lang = Language.English
exercises: List[Exercise] = db.session.query(Exercise).filter_by(language=lang.value) exercises: List[Exercise] = db.session.query(Exercise).filter_by(language=lang.value)
db.session.commit()
ret_val: List[dict] = [NetworkService.serialize_exercise(x, compress=True) for x in exercises] ret_val: List[dict] = [NetworkService.serialize_exercise(x, compress=True) for x in exercises]
matching_degrees: List[float] = [] matching_degrees: List[float] = []
if len(vocabulary_set): if len(vocabulary_set):
......
...@@ -44,6 +44,7 @@ class FileAPI(Resource): ...@@ -44,6 +44,7 @@ class FileAPI(Resource):
args = self.reqparse.parse_args() args = self.reqparse.parse_args()
eid: str = args["id"] eid: str = args["id"]
exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first() exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
file_type: FileType = FileType[args["type"]] file_type: FileType = FileType[args["type"]]
file_name: str = eid + "." + file_type.value file_name: str = eid + "." + file_type.value
mime_type: str = MimeType[file_type.value].value mime_type: str = MimeType[file_type.value].value
......
...@@ -73,6 +73,7 @@ class H5pAPI(Resource): ...@@ -73,6 +73,7 @@ class H5pAPI(Resource):
except ValueError: except ValueError:
lang = Language.English lang = Language.English
exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first() exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
if exercise is None: if exercise is None:
abort(404) abort(404)
text_field_content: str = "" text_field_content: str = ""
......
...@@ -338,6 +338,7 @@ class CorpusService: ...@@ -338,6 +338,7 @@ class CorpusService:
def update_corpora(): def update_corpora():
"""Checks the remote repositories for new corpora to be included in our database.""" """Checks the remote repositories for new corpora to be included in our database."""
CorpusService.existing_corpora = db.session.query(Corpus).all() CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
resolver: HttpCtsRetriever = HttpCtsRetriever(Config.CTS_API_BASE_URL) resolver: HttpCtsRetriever = HttpCtsRetriever(Config.CTS_API_BASE_URL)
# check the appropriate literature for the desired author # check the appropriate literature for the desired author
resp: str = resolver.getCapabilities(urn="urn:cts:latinLit") # "urn:cts:greekLit" for Greek resp: str = resolver.getCapabilities(urn="urn:cts:latinLit") # "urn:cts:greekLit" for Greek
...@@ -373,6 +374,7 @@ class CorpusService: ...@@ -373,6 +374,7 @@ class CorpusService:
db.session.delete(corpus_to_delete) db.session.delete(corpus_to_delete)
db.session.commit() db.session.commit()
CorpusService.existing_corpora = db.session.query(Corpus).all() CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
@staticmethod @staticmethod
def update_corpus(title_value: str, urn: str, author: str, def update_corpus(title_value: str, urn: str, author: str,
......
...@@ -43,6 +43,7 @@ class DatabaseService: ...@@ -43,6 +43,7 @@ class DatabaseService:
"""Initializes the corpus list if it is not already there and up to date.""" """Initializes the corpus list if it is not already there and up to date."""
if db.engine.dialect.has_table(db.engine, "Corpus"): if db.engine.dialect.has_table(db.engine, "Corpus"):
CorpusService.existing_corpora = db.session.query(Corpus).all() CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
urn_dict: Dict[str, int] = {v.source_urn: i for i, v in enumerate(CorpusService.existing_corpora)} urn_dict: Dict[str, int] = {v.source_urn: i for i, v in enumerate(CorpusService.existing_corpora)}
for cc in CustomCorpusService.custom_corpora: for cc in CustomCorpusService.custom_corpora:
if cc.corpus.source_urn in urn_dict: if cc.corpus.source_urn in urn_dict:
...@@ -59,6 +60,7 @@ class DatabaseService: ...@@ -59,6 +60,7 @@ class DatabaseService:
group_name_value=cc.corpus.author, group_name_value=cc.corpus.author,
citation_levels=citation_levels) citation_levels=citation_levels)
CorpusService.existing_corpora = db.session.query(Corpus).all() CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
@staticmethod @staticmethod
def init_db_update_info() -> None: def init_db_update_info() -> None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment