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]:
return NetworkService.make_json_response(None)
if ui_cts.last_modified_time >= last_update_time / 1000:
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(None)
......@@ -27,6 +27,7 @@ def adjust_solutions(exercise_data: ExerciseData, exercise_type: str, solutions:
def get(eid: str) -> Union[Response, ConnexionResponse]:
exercise: TExercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
if exercise is None:
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)
......
......@@ -34,6 +34,7 @@ class ExerciseListAPI(Resource):
last_update: int = args["last_update_time"]
ui_exercises: UpdateInfo = db.session.query(UpdateInfo).filter_by(
resource_type=ResourceType.exercise_list.name).first()
db.session.commit()
if ui_exercises.last_modified_time < last_update / 1000:
return NetworkService.make_json_response([])
try:
......@@ -47,6 +48,7 @@ class ExerciseListAPI(Resource):
except ValueError:
lang = Language.English
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]
matching_degrees: List[float] = []
if len(vocabulary_set):
......
......@@ -44,6 +44,7 @@ class FileAPI(Resource):
args = self.reqparse.parse_args()
eid: str = args["id"]
exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
file_type: FileType = FileType[args["type"]]
file_name: str = eid + "." + file_type.value
mime_type: str = MimeType[file_type.value].value
......
......@@ -73,6 +73,7 @@ class H5pAPI(Resource):
except ValueError:
lang = Language.English
exercise: Exercise = db.session.query(Exercise).filter_by(eid=eid).first()
db.session.commit()
if exercise is None:
abort(404)
text_field_content: str = ""
......
......@@ -338,6 +338,7 @@ class CorpusService:
def update_corpora():
"""Checks the remote repositories for new corpora to be included in our database."""
CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
resolver: HttpCtsRetriever = HttpCtsRetriever(Config.CTS_API_BASE_URL)
# check the appropriate literature for the desired author
resp: str = resolver.getCapabilities(urn="urn:cts:latinLit") # "urn:cts:greekLit" for Greek
......@@ -373,6 +374,7 @@ class CorpusService:
db.session.delete(corpus_to_delete)
db.session.commit()
CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
@staticmethod
def update_corpus(title_value: str, urn: str, author: str,
......
......@@ -43,6 +43,7 @@ class DatabaseService:
"""Initializes the corpus list if it is not already there and up to date."""
if db.engine.dialect.has_table(db.engine, "Corpus"):
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)}
for cc in CustomCorpusService.custom_corpora:
if cc.corpus.source_urn in urn_dict:
......@@ -59,6 +60,7 @@ class DatabaseService:
group_name_value=cc.corpus.author,
citation_levels=citation_levels)
CorpusService.existing_corpora = db.session.query(Corpus).all()
db.session.commit()
@staticmethod
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