22from collections import defaultdict
33from flasgger import Swagger
44import re ,os ,traceback
5- from query import PostgresORM
5+ # from query import PostgresORM
66from utils import *
77from flask_cors import CORS ,cross_origin
88from v2_app import v2
99from flask_sqlalchemy import SQLAlchemy
1010from models import db
11+ from shared_migrations .db import get_postgres_uri
12+ from shared_migrations .db .dmp_api import DmpAPIQueries
13+ from sqlalchemy .ext .asyncio import create_async_engine , AsyncSession
14+ from sqlalchemy .orm import sessionmaker
15+ from sqlalchemy .pool import NullPool
1116
1217
1318
1419app = Flask (__name__ )
1520CORS (app ,supports_credentials = True )
1621
1722
18- app .config ['SQLALCHEMY_DATABASE_URI' ] = PostgresORM . get_postgres_uri ()
23+ app .config ['SQLALCHEMY_DATABASE_URI' ] = get_postgres_uri ()
1924app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
2025
26+ # Initialize Async SQLAlchemy
27+ engine = create_async_engine (app .config ['SQLALCHEMY_DATABASE_URI' ], echo = False ,poolclass = NullPool )
28+ async_session = sessionmaker (autocommit = False , autoflush = False , bind = engine , class_ = AsyncSession )
29+
30+
2131db .init_app (app )
2232
2333Swagger (app )
@@ -56,9 +66,9 @@ def greeting():
5666
5767
5868@app .route ('/issues' , methods = ['GET' ])
59- @cross_origin (supports_credentials = True )
60- @require_secret_key
61- def get_issues ():
69+ # @cross_origin(supports_credentials=True)
70+ # @require_secret_key
71+ async def get_issues ():
6272 """
6373 Fetch all issues and group by owner.
6474 ---
@@ -80,8 +90,9 @@ def get_issues():
8090 type: string
8191 """
8292 try :
83- # Fetch all issues with their details
84- data = PostgresORM .get_issue_query ()
93+ # Fetch all issues with their details
94+ print ('inside get all issues' )
95+ data = await DmpAPIQueries .get_issue_query (async_session )
8596 response = []
8697
8798 for result in data :
@@ -98,9 +109,9 @@ def get_issues():
98109 return jsonify ({'error' : str (e ), 'traceback' : error_traceback }), 500
99110
100111@app .route ('/issues/<owner>' , methods = ['GET' ])
101- @cross_origin (supports_credentials = True )
102- @require_secret_key
103- def get_issues_by_owner (owner ):
112+ # @cross_origin(supports_credentials=True)
113+ # @require_secret_key
114+ async def get_issues_by_owner (owner ):
104115 """
105116 Fetch organization details by owner's GitHub URL.
106117 ---
@@ -142,7 +153,7 @@ def get_issues_by_owner(owner):
142153 try :
143154
144155 # Fetch organization details from dmp_orgs table
145- response = PostgresORM .get_issue_owner (owner )
156+ response = await DmpAPIQueries .get_issue_owner (async_session , owner )
146157 if not response :
147158 return jsonify ({'error' : "Organization not found" }), 404
148159
@@ -192,7 +203,7 @@ def get_issues_by_owner_id(owner, issue):
192203 """
193204 try :
194205 print ('inside get issues' )
195- SUPABASE_DB = SupabaseInterface () .get_instance ()
206+ SUPABASE_DB = DmpAPIQueries .get_instance ()
196207 response = SUPABASE_DB .client .table ('dmp_issue_updates' ).select ('*' ).eq ('owner' , owner ).eq ('issue_number' , issue ).execute ()
197208 if not response .data :
198209 return jsonify ({'error' : "No data found" }), 200
0 commit comments