Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shreyansb/1297323 to your computer and use it in GitHub Desktop.
Save shreyansb/1297323 to your computer and use it in GitHub Desktop.
Way to improve this
@classmethod
def get_matches_for_status_matched(klass, ride_doc):
ride=[]
# first ensure status is matched
if ride_doc.get(Ride.A_STATUS) != 2: return ride
# get the match ride and user info
match_ride_id = ride_doc.get(Ride.A_MATCH_ID)
if not match_ride_id: return ride
match_ride = klass.get_ride(match_ride_id)
if not match_ride: return ride
user_id = match_ride_id.get(klass.A_USER_ID)
if not user_id: return ride
user_doc = UserHelper.get_users_by_id(user_id)
if not user_doc: return ride
# link the
if user_doc:
match_ride["user"]=user_doc
ride = match_ride
return ride
@shreyansb
Copy link
Author

This is one quick improvement - less nested.
Each time you do 'return ride', you could instead raise a specific error if you wanted to (later)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment