Skip to content

Commit

Permalink
add sqltap profiling agsi
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Nov 15, 2023
1 parent 101c64f commit 15bfc12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions store/neurostore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@
from connexion.resolver import MethodResolver
from flask_caching import Cache
import sqltap.wsgi
import sqltap

from .or_json import ORJSONDecoder, ORJSONEncoder
from .database import init_db


class SQLTapMiddleware:
def __init__(self, app):
self.app = app

async def __call__(self, scope, receive, send):
profiler = sqltap.start()
await self.app(scope, receive, send)
statistics = profiler.collect()
sqltap.report(statistics, "report.txt", report_format="text")


connexion_app = connexion.FlaskApp(__name__, specification_dir="openapi/")

app = connexion_app.app
Expand Down Expand Up @@ -45,6 +57,11 @@
allow_headers=["*"],
)

# add sqltap
connexion_app.add_middleware(
SQLTapMiddleware,
)

connexion_app.add_api(
openapi_file,
base_path="/api",
Expand Down
3 changes: 2 additions & 1 deletion store/neurostore/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class BaseStudy(BaseMixin, db.Model):
user = relationship("User", backref=backref("base_studies"))
# retrieve versions of same study
versions = relationship(
"Study", backref=backref("base_study"))
"Study", backref=backref("base_study")
)

def update_has_images_and_points(self):
# Calculate has_images and has_coordinates for the BaseStudy
Expand Down
2 changes: 1 addition & 1 deletion store/neurostore/tests/api/test_studysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_post_and_get_studysets(auth_client, ingest_neurosynth, session):
== post_resp.json()
)

@add_event_listeners
# @add_event_listeners
def test_add_many_studies_to_studyset(auth_client, ingest_neurosynth, session):
existing_studies = Study.query.all()
existing_study_ids = [s.id for s in existing_studies]
Expand Down

0 comments on commit 15bfc12

Please sign in to comment.