bkyryliuk opened a new pull request, #20974:
URL: https://github.com/apache/superset/pull/20974

   ### SUMMARY
   Implement model specific lookups by id to improve the explore endpoint 
performance.
   Existing implementation was spending ~500 ms in our deployment on doing 
object by id lookup and that contributed to ~1 - 1.5 second slowdown of the 
explore endpoint.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   ### Before
   <img width="940" alt="Screen Shot 2022-08-03 at 1 41 41 PM" 
src="https://user-images.githubusercontent.com/5727938/182892252-13a4e1eb-0b8e-47ed-885a-5fa0dc9310cd.png";>
   ### After
   <img width="952" alt="image" 
src="https://user-images.githubusercontent.com/5727938/182893558-19e11aa6-2f80-42fe-a54d-0da6928827d2.png";>
   
   <img width="933" alt="Screen Shot 2022-08-04 at 8 46 54 AM" 
src="https://user-images.githubusercontent.com/5727938/182893202-6a543f0b-389e-418c-b72a-cc9a4178ef3a.png";>
   
   
   ### TESTING INSTRUCTIONS
   [] Deployed and tested on dropbox staging
   ### ADDITIONAL INFORMATION
   More granular breakdown
   ```
   @classmethod
   def find_by_id(
       cls, model_id: Union[str, int], session: Session = None
   ) -> Optional[Model]:
       """
       Find a model by id, if defined applies `base_filter`
       """
       with 
newrelic.agent.FunctionTrace("superset.dao.base.find_by_id.session", 
group="DAO"):
           session = session or db.session
       with 
newrelic.agent.FunctionTrace("superset.dao.base.find_by_id.query_contruction", 
group="DAO"):
           query = session.query(cls.model_cls)
           if cls.base_filter:
               data_model = SQLAInterface(cls.model_cls, session)
               query = cls.base_filter(  # pylint: disable=not-callable
                   cls.id_column_name, data_model
               ).apply(query, None)
           id_filter = {cls.id_column_name: model_id}
       try:
           with 
newrelic.agent.FunctionTrace("superset.dao.base.find_by_id.query_execution", 
group="DAO"):
               return query.filter_by(**id_filter).one_or_none()
       except StatementError:
           # can happen if int is passed instead of a string or similar
           return None
   ````
   
   
   ![Screen Shot 2022-08-03 at 5 00 28 
PM](https://user-images.githubusercontent.com/5727938/182892646-34116d3b-b053-436d-9e0b-bee6371d8302.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to