In [1]:
import os, sys

ROOT_DIR = '/path/to/git/ozp-backend'

sys.path.insert(0, ROOT_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ozp.settings")

import django

django.setup()

In [2]:
from rest_framework.response import Response
import ozpcenter.api.storefront.model_access as ma
import ozpcenter.api.storefront.serializers as se
import timeit
from django.test.client import RequestFactory

rf = RequestFactory()
get_request = rf.get('/hello/')

get_request.user = 'bigbrother'
get_request.query_params = {'randomize': True}

In [3]:
data = ma.get_storefront(get_request) # Database calls
data


2018-01-31 14:44:29,459 - INFO - plugin_manager - Success Loading Plugin: (<module 'plugins.default_access_control.main' from '/home/irizvi/git/ozp-backend/plugins/default_access_control/main.py'>,<class 'plugins.default_access_control.main.PluginMain'>,False)
2018-01-31 14:44:29,462 - INFO - plugin_manager - Success Loading Plugin: (<module 'plugins.default_authorization.main' from '/home/irizvi/git/ozp-backend/plugins/default_authorization/main.py'>,<class 'plugins.default_authorization.main.PluginMain'>,False)
Out[3]:
({'featured': [(ozp.test.air_mail-['wsmith']),
   (bass_fishing-['bettafish', 'jones']),
   (ozp.test.bread_basket-['julia']),
   (ozp.test.chartcourse-['wsmith']),
   (ozp.test.chatterbox-['julia']),
   (ozp.test.clipboard-['wsmith']),
   (ozp.test.frameit-['wsmith']),
   (harley-davidson_cvo-['bettafish', 'jones']),
   (ozp.test.hatchlatch-['wsmith']),
   (ozp.test.jotspot-['wsmith']),
   (ozp.test.locationanalyzer-['wsmith']),
   (ozp.test.locationlister-['wsmith']),
   (ozp.test.locationviewer-['wsmith']),
   (ozp.test.skybox-['david', 'pmurt']),
   (tornado-['bigbrother'])],
  'most_popular': [(global_navigation_grid_code-['rutherford']),
   (map_of_the_world-['rutherford']),
   (stop_sign-['bettafish']),
   (sun-['betaraybill']),
   (astrology_software-['bettafish']),
   (baltimore_ravens-['bettafish']),
   (barbecue-['jones']),
   (dragons-['bigbrother2', 'khaleesi']),
   (house_targaryen-['khaleesi']),
   (informational_book-['bigbrother']),
   (motorcycle_helmet-['bettafish']),
   (phentolamine-['bettafish']),
   (ruby-['wsmith']),
   (stout-['bettafish']),
   (waterme_lon-['aaronson']),
   (bleach-['bettafish', 'wsmith']),
   (wolf_finder-['bigbrother']),
   (barsoom-['betaraybill']),
   (iron_man-['syme']),
   (jean_grey-['syme']),
   (azeroth-['betaraybill']),
   (navigation-['rutherford']),
   (hawaii-['aaronson']),
   (railroad-['rutherford']),
   (ten-['bettafish']),
   (beast-['syme']),
   (great_white_shark-['bigbrother']),
   (jupiter-['betaraybill']),
   (satellite_navigation-['rutherford']),
   (saturn-['betaraybill']),
   (superunknown-['bettafish']),
   (bass_fishing-['bettafish', 'jones']),
   (chasing_amy-['bettafish']),
   (ozp.test.jotspot-['wsmith']),
   (ozp.test.locationlister-['wsmith']),
   (mallrats-['bettafish'])],
  'recent': [(writing-['bigbrother']),
   (wolverine-['syme']),
   (wolf_finder-['bigbrother']),
   (wii-['bettafish']),
   (white-tailed_olalla_rat-['bettafish']),
   (white_horse-['bigbrother']),
   (waterme_lon-['aaronson']),
   (violin-['bigbrother']),
   (venus-['betaraybill']),
   (uranus-['betaraybill']),
   (transport_direct_portal-['rutherford']),
   (toyota-['bettafish']),
   (tornado-['bigbrother']),
   (tiny_music..._songs_from_the_vatican_gift_shop-['bettafish']),
   (tennis-['bettafish']),
   (ten-['bettafish']),
   (taxonomy_classifier-['bigbrother']),
   (t-slot_nut-['bettafish']),
   (superunknown-['bettafish']),
   (sun-['betaraybill']),
   (sudovian_book-['bettafish']),
   (stroke_play-['jones']),
   (stout-['bettafish']),
   (stop_sign-['bettafish'])],
  'recommended': [(ozp.test.air_mail-['wsmith']),
   (baltimore_ravens-['bettafish']),
   (azeroth-['betaraybill']),
   (bass_fishing-['bettafish', 'jones']),
   (dragons-['bigbrother2', 'khaleesi']),
   (house_targaryen-['khaleesi']),
   (ozp.test.jotspot-['wsmith']),
   (ozp.test.locationlister-['wsmith']),
   (iron_man-['syme']),
   (saturn-['betaraybill'])]},
 {'recommender_profile_result_set': {'Baseline': {'weight': 1.0, 'ms_took': 2715.857177734375, 'recommendations': {1: 7.0, 2: 11.2, 4: 5.3, 5: 2.0, 6: 3.0, 7: 2.0, 8: 7.0, 9: 11.2, 10: 12.0, 11: 7.0, 12: 6.3, 13: 5.5, 14: 9.0, 15: 2.0, 16: 6.0, 17: 5.5, 18: 8.5, 19: 5.7, 20: 2.0, 21: 4.0, 22: 2.0, 23: 11.5, 24: 2.0, 25: 5.0, 26: 2.0, 27: 5.0, 28: 2.0, 29: 4.0, 30: 11.5, 31: 6.0, 32: 3.0, 33: 2.0, 34: 2.0, 35: 2.0, 36: 5.0, 37: 5.0, 38: 3.0, 39: 2.0, 40: 2.0, 41: 5.0, 42: 5.5, 43: 2.0, 44: 4.0, 45: 5.3, 46: 2.0, 47: 9.0, 48: 2.0, 49: 4.0, 50: 4.0, 52: 2.0, 53: 2.0, 54: 2.0, 55: 5.0, 56: 5.2, 57: 2.0, 58: 3.0, 59: 7.5, 60: 2.0, 61: 7.0, 62: 2.0, 63: 4.0, 64: 6.0, 65: 6.0, 66: 3.0, 67: 6.0, 68: 5.0, 69: 6.5, 70: 9.0, 71: 2.0, 72: 4.0, 73: 9.0, 74: 2.0, 75: 2.0, 76: 4.0, 77: 8.3, 78: 5.0, 79: 5.5, 80: 3.0, 81: 8.3, 82: 9.0, 83: 6.0, 84: 2.0, 85: 2.0, 86: 2.0, 87: 10.5, 88: 3.0, 89: 5.7, 90: 7.5, 91: 2.0, 93: 4.0, 94: 5.0, 95: 3.0, 96: 9.0, 97: 3.0, 98: 2.0, 99: 5.0, 100: 4.0, 101: 11.0, 102: 7.0, 103: 4.0, 104: 5.5, 105: 3.8, 106: 2.0, 107: 3.0, 108: 5.0, 109: 5.5, 110: 2.0, 111: 7.0, 112: 5.5, 113: 2.0, 114: 2.0, 115: 4.0, 116: 8.2, 117: 5.5, 118: 5.0, 119: 6.0, 120: 2.0, 121: 2.0, 122: 4.0, 123: 2.0, 124: 2.0, 125: 7.0, 126: 2.0, 127: 4.0, 128: 5.0, 129: 2.0, 131: 2.0, 132: 5.0, 133: 3.5, 134: 6.0, 135: 4.0, 136: 7.0, 137: 2.0, 138: 2.0, 139: 2.0, 140: 2.0, 141: 2.0, 142: 5.0, 143: 2.0, 145: 2.0, 146: 6.0, 147: 8.0, 148: 4.0, 149: 2.0, 150: 2.0, 151: 2.0, 152: 3.0, 153: 2.0, 154: 6.0, 155: 2.0, 156: 4.0, 158: 9.0, 159: 7.0, 160: 5.0, 161: 2.0, 162: 7.0, 163: 6.0, 164: 2.0, 165: 2.0, 166: 6.0, 167: 2.0, 168: 5.5, 169: 6.0, 170: 2.0, 171: 2.0, 173: 5.5, 174: 4.5, 175: 4.0, 178: 6.7, 180: 8.0, 181: 2.0, 182: 2.0, 186: 11.5, 187: 5.0, 188: 2.0}}, 'Bookmark Collaborative Filtering': {'weight': 5.0, 'ms_took': 10.505126953125, 'recommendations': {96: 1.0, 2: 2.0, 68: 1.0, 69: 1.0, 70: 1.0, 9: 1.0, 10: 1.0, 44: 1.0, 77: 1.0, 14: 1.0, 47: 1.0, 81: 1.0, 82: 1.0, 147: 1.0, 90: 1.0, 63: 1.0, 101: 1.0}}}})

In [4]:
%timeit ma.get_storefront(get_request)


158 ms ± 10.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [5]:
%prun -l 100 ma.get_storefront(get_request)


 

In [6]:
import profile

profile.run('ma.get_storefront(get_request)', 'get_storefront_stats.ipynb_stats')

In [7]:
import pstats

p = pstats.Stats('get_storefront_stats.ipynb_stats')
p.strip_dirs()
p.sort_stats('cumtime')
p.print_stats()


Wed Jan 31 14:44:46 2018    get_storefront_stats.ipynb_stats

         238669 function calls (235022 primitive calls) in 1.267 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    1.267    1.267 profile:0(ma.get_storefront(get_request))
        1    0.000    0.000    1.266    1.266 :0(exec)
        1    0.000    0.000    1.266    1.266 <string>:1(<module>)
        1    0.000    0.000    1.266    1.266 model_access.py:370(get_storefront)
       40    0.003    0.000    1.135    0.028 query.py:1116(_fetch_all)
      489    0.015    0.000    1.132    0.002 query.py:47(__iter__)
       12    0.000    0.000    0.896    0.075 query.py:235(__iter__)
     5210    0.052    0.000    0.476    0.000 base.py:576(from_db)
       39    0.002    0.000    0.447    0.011 compiler.py:855(execute_sql)
5552/3571    0.045    0.000    0.423    0.000 query.py:1740(populate)
        1    0.000    0.000    0.421    0.421 model_access.py:297(get_storefront_recommended)
     5210    0.228    0.000    0.405    0.000 base.py:472(__init__)
        1    0.000    0.000    0.403    0.403 recommend.py:247(process)
        1    0.000    0.000    0.372    0.372 model_access.py:352(get_storefront_most_popular)
        1    0.000    0.000    0.366    0.366 model_access.py:334(get_storefront_recent)
       39    0.019    0.000    0.314    0.008 compiler.py:413(as_sql)
23007/22647    0.054    0.000    0.292    0.000 :0(len)
       27    0.000    0.000    0.281    0.010 query.py:366(get)
        1    0.000    0.000    0.274    0.274 recommend.py:179(_filter_listings)
       39    0.001    0.000    0.254    0.007 compiler.py:40(pre_sql_setup)
       39    0.001    0.000    0.246    0.006 compiler.py:34(setup_query)
       39    0.021    0.001    0.245    0.006 compiler.py:165(get_select)
       28    0.000    0.000    0.239    0.009 query.py:231(__len__)
       32    0.000    0.000    0.227    0.007 related_descriptors.py:161(__get__)
       21    0.000    0.000    0.225    0.011 related_descriptors.py:156(get_object)
      489    0.003    0.000    0.132    0.000 compiler.py:831(results_iter)
    48675    0.118    0.000    0.118    0.000 :0(setattr)
       79    0.001    0.000    0.103    0.001 compiler.py:1277(cursor_iter)
       79    0.001    0.000    0.102    0.001 compiler.py:1283(<lambda>)
        1    0.000    0.000    0.101    0.101 recommend.py:223(_fix_recommendation_order)
       79    0.001    0.000    0.100    0.001 utils.py:99(inner)
       79    0.023    0.000    0.099    0.001 :0(fetchmany)
1961/1834    0.022    0.000    0.096    0.000 compiler.py:368(compile)
    78/12    0.025    0.000    0.090    0.008 compiler.py:672(get_related_selections)
        1    0.000    0.000    0.085    0.085 model_access.py:316(get_storefront_featured)
     3399    0.018    0.000    0.082    0.000 base.py:65(<lambda>)
       47    0.001    0.000    0.073    0.002 query.py:793(_filter_or_exclude)
        8    0.000    0.000    0.072    0.009 manager.py:84(manager_method)
        4    0.000    0.000    0.070    0.017 models.py:1046(for_user_organization_minus_security_markings)
      424    0.020    0.000    0.067    0.000 compiler.py:822(apply_converters)
      105    0.017    0.000    0.066    0.001 compiler.py:523(get_default_columns)
       41    0.000    0.000    0.062    0.002 query.py:779(filter)
       47    0.001    0.000    0.062    0.001 query.py:1237(add_q)
       39    0.009    0.000    0.062    0.002 compiler.py:812(get_converters)
    68/47    0.003    0.000    0.060    0.001 query.py:1255(_add_q)
     1244    0.023    0.000    0.055    0.000 dateparse.py:85(parse_datetime)
       63    0.005    0.000    0.045    0.001 query.py:1122(build_filter)
     1740    0.013    0.000    0.039    0.000 expressions.py:693(as_sql)
     3252    0.013    0.000    0.038    0.000 operations.py:216(convert_datetimefield_value)
     1677    0.012    0.000    0.034    0.000 expressions.py:703(get_db_converters)
    10202    0.033    0.000    0.033    0.000 :0(append)
      150    0.002    0.000    0.030    0.000 query.py:1102(_clone)
      134    0.003    0.000    0.030    0.000 query.py:1389(setup_joins)
     1745    0.013    0.000    0.030    0.000 __init__.py:353(get_col)
      150    0.005    0.000    0.027    0.000 query.py:266(clone)
     3741    0.016    0.000    0.027    0.000 compiler.py:351(quote_name_unless_alias)
       39    0.001    0.000    0.025    0.001 utils.py:77(execute)
        1    0.000    0.000    0.025    0.025 recommend.py:209(_get_listing_queryset)
        1    0.000    0.000    0.022    0.022 models.py:407(for_user_organization_minus_security_markings)
      335    0.002    0.000    0.021    0.000 related.py:1007(get_col)
       39    0.001    0.000    0.019    0.000 utils.py:59(execute)
        5    0.000    0.000    0.019    0.004 models.py:59(get_user_excluded_orgs)
        5    0.000    0.000    0.019    0.004 models.py:886(highest_role)
     1677    0.013    0.000    0.019    0.000 operations.py:199(get_db_converters)
    10420    0.019    0.000    0.019    0.000 dispatcher.py:170(send)
     6555    0.015    0.000    0.019    0.000 :0(isinstance)
       39    0.010    0.000    0.019    0.000 base.py:324(execute)
        1    0.000    0.000    0.018    0.018 recommend.py:119(from_profile_instance)
     3121    0.012    0.000    0.018    0.000 __init__.py:471(__eq__)
     1244    0.006    0.000    0.017    0.000 timezone.py:277(make_aware)
     6505    0.017    0.000    0.017    0.000 :0(iter)
        4    0.000    0.000    0.017    0.004 pipeline.py:120(to_list)
       89    0.000    0.000    0.016    0.000 pipeline.py:97(next)
   169/89    0.001    0.000    0.016    0.000 pipes.py:37(next)
       70    0.001    0.000    0.016    0.000 query.py:876(select_related)
     6279    0.016    0.000    0.016    0.000 :0(hasattr)
      134    0.002    0.000    0.015    0.000 query.py:903(join)
       86    0.001    0.000    0.015    0.000 pipes.py:265(process_next_start)
        1    0.000    0.000    0.015    0.015 query.py:560(first)
      197    0.006    0.000    0.014    0.000 query.py:1284(names_to_path)
       85    0.002    0.000    0.014    0.000 plugin_manager.py:211(system_has_access_control)
        4    0.000    0.000    0.014    0.003 models.py:1004(apply_select_related)
    45/39    0.001    0.000    0.014    0.000 where.py:63(as_sql)
      193    0.003    0.000    0.013    0.000 __init__.py:41(__init__)
       73    0.000    0.000    0.013    0.000 pipes.py:335(process_next_start)
      150    0.001    0.000    0.012    0.000 __init__.py:211(copy)
     2000    0.007    0.000    0.012    0.000 __init__.py:672(get_db_converters)
       26    0.000    0.000    0.012    0.000 manager.py:153(all)
 1332/652    0.005    0.000    0.011    0.000 functional.py:32(__get__)
        6    0.000    0.000    0.011    0.002 query.py:786(exclude)
       58    0.001    0.000    0.010    0.000 lookups.py:168(as_sql)
     1244    0.006    0.000    0.010    0.000 six.py:580(iteritems)
       85    0.000    0.000    0.010    0.000 cache.py:30(_decorator)
     2458    0.010    0.000    0.010    0.000 :0(extend)
     3026    0.010    0.000    0.010    0.000 :0(getattr)
        5    0.000    0.000    0.010    0.002 related_descriptors.py:878(get_queryset)
     2531    0.010    0.000    0.010    0.000 :0(get)
       85    0.001    0.000    0.010    0.000 cache.py:78(get)
        5    0.000    0.000    0.010    0.002 related_descriptors.py:863(_apply_rel_filters)
      483    0.005    0.000    0.009    0.000 related.py:651(foreign_related_fields)
     1244    0.005    0.000    0.009    0.000 __init__.py:224(localize)
      134    0.003    0.000    0.009    0.000 query.py:916(<listcomp>)
     1517    0.006    0.000    0.009    0.000 operations.py:147(quote_name)
      193    0.004    0.000    0.009    0.000 _collections_abc.py:575(update)
       56    0.001    0.000    0.009    0.000 query.py:1081(build_lookup)
     5210    0.009    0.000    0.009    0.000 base.py:462(__init__)
       85    0.001    0.000    0.009    0.000 default.py:189(get)
       39    0.001    0.000    0.008    0.000 compiler.py:638(get_from_clause)
      332    0.001    0.000    0.008    0.000 related.py:907(target_field)
       31    0.000    0.000    0.007    0.000 query.py:957(order_by)
     4135    0.007    0.000    0.007    0.000 operations.py:247(convert_booleanfield_value)
       63    0.002    0.000    0.007    0.000 query.py:1025(solve_lookup_type)
     3399    0.006    0.000    0.006    0.000 :0(decode)
      612    0.002    0.000    0.006    0.000 expressions.py:231(output_field)
      180    0.002    0.000    0.006    0.000 copy.py:67(copy)
     1677    0.006    0.000    0.006    0.000 query.py:934(join_parent_model)
     1244    0.006    0.000    0.006    0.000 dateparse.py:108(<dictcomp>)
     1248    0.006    0.000    0.006    0.000 :0(match)
       58    0.001    0.000    0.006    0.000 lookups.py:158(process_lhs)
     1244    0.004    0.000    0.006    0.000 timezone.py:251(is_aware)
      677    0.003    0.000    0.006    0.000 <frozen importlib._bootstrap>:2264(_handle_fromlist)
       21    0.000    0.000    0.005    0.000 related_descriptors.py:109(get_queryset)
  223/150    0.002    0.000    0.005    0.000 where.py:140(clone)
     1283    0.005    0.000    0.005    0.000 :0(replace)
       63    0.001    0.000    0.005    0.000 lookups.py:22(__init__)
       63    0.001    0.000    0.005    0.000 query_utils.py:147(get_lookup)
      123    0.001    0.000    0.005    0.000 related.py:719(get_path_info)
     2162    0.004    0.000    0.004    0.000 :0(items)
       56    0.000    0.000    0.004    0.000 expressions.py:298(get_lookup)
     1244    0.004    0.000    0.004    0.000 :0(groupdict)
       74    0.002    0.000    0.004    0.000 datastructures.py:60(as_sql)
      612    0.003    0.000    0.004    0.000 expressions.py:683(__init__)
      152    0.002    0.000    0.004    0.000 __init__.py:517(update)
      953    0.004    0.000    0.004    0.000 :0(add)
       84    0.001    0.000    0.004    0.000 query.py:2084(add_votes)
       68    0.001    0.000    0.004    0.000 query.py:2091(update_join_types)
      119    0.001    0.000    0.004    0.000 query.py:883(get_initial_alias)
      628    0.002    0.000    0.004    0.000 _collections_abc.py:496(__iter__)
   105/39    0.001    0.000    0.004    0.000 query.py:1757(get_related_populators)
      304    0.002    0.000    0.004    0.000 abc.py:178(__instancecheck__)
       39    0.001    0.000    0.003    0.000 operations.py:128(last_executed_query)
      654    0.002    0.000    0.003    0.000 related.py:637(related_fields)
      323    0.002    0.000    0.003    0.000 related.py:1001(get_db_converters)
       85    0.001    0.000    0.003    0.000 default.py:308(decode)
      189    0.001    0.000    0.003    0.000 query.py:161(__init__)
     2155    0.003    0.000    0.003    0.000 base.py:68(<lambda>)
       63    0.001    0.000    0.003    0.000 query.py:980(prepare_lookup_value)
       39    0.000    0.000    0.003    0.000 where.py:30(split_having)
       39    0.001    0.000    0.003    0.000 compiler.py:234(get_order_by)
       21    0.000    0.000    0.003    0.000 manager.py:132(db_manager)
       39    0.000    0.000    0.003    0.000 manager.py:146(get_queryset)
     1244    0.003    0.000    0.003    0.000 :0(ljust)
      112    0.001    0.000    0.003    0.000 datastructures.py:43(__init__)
        7    0.000    0.000    0.003    0.000 lookups.py:377(as_sql)
     1408    0.003    0.000    0.003    0.000 query.py:1918(extra_select)
       63    0.001    0.000    0.003    0.000 query_utils.py:137(_get_lookup)
     1677    0.003    0.000    0.003    0.000 __init__.py:367(select_format)
     1528    0.003    0.000    0.003    0.000 :0(startswith)
      242    0.002    0.000    0.003    0.000 tree.py:83(add)
    66/45    0.001    0.000    0.003    0.000 query.py:1675(__init__)
     1356    0.003    0.000    0.003    0.000 :0(pop)
      489    0.002    0.000    0.003    0.000 datastructures.py:108(__eq__)
     1677    0.003    0.000    0.003    0.000 operations.py:544(get_db_converters)
       39    0.000    0.000    0.003    0.000 where.py:166(contains_aggregate)
       39    0.001    0.000    0.003    0.000 operations.py:101(_quote_params_for_last_executed_query)
      324    0.002    0.000    0.003    0.000 __init__.py:62(__setitem__)
      203    0.002    0.000    0.003    0.000 utils.py:204(__getitem__)
       21    0.000    0.000    0.003    0.000 related.py:363(get_reverse_related_filter)
   108/39    0.001    0.000    0.003    0.000 where.py:160(_contains_aggregate)
       39    0.000    0.000    0.003    0.000 base.py:250(cursor)
       30    0.001    0.000    0.002    0.000 copy.py:272(_reconstruct)
       39    0.001    0.000    0.002    0.000 query.py:128(__init__)
        1    0.000    0.000    0.002    0.002 recommend.py:234(_get_recommended_listings)
       39    0.001    0.000    0.002    0.000 base.py:228(_cursor)
       63    0.001    0.000    0.002    0.000 functools.py:440(wrapper)
      112    0.001    0.000    0.002    0.000 related.py:683(get_joining_columns)
    45/39    0.000    0.000    0.002    0.000 :0(any)
       85    0.000    0.000    0.002    0.000 client.py:294(get)
      116    0.001    0.000    0.002    0.000 query_utils.py:63(__init__)
      115    0.001    0.000    0.002    0.000 query.py:772(demote_joins)
     1041    0.002    0.000    0.002    0.000 __init__.py:87(__iter__)
       51    0.001    0.000    0.002    0.000 lookups.py:84(process_rhs)
       68    0.001    0.000    0.002    0.000 query.py:1434(trim_joins)
       68    0.000    0.000    0.002    0.000 query.py:2069(__init__)
        6    0.000    0.000    0.002    0.000 models.py:789(get_queryset)
   114/97    0.000    0.000    0.002    0.000 where.py:163(<genexpr>)
      966    0.002    0.000    0.002    0.000 related.py:653(<genexpr>)
      101    0.001    0.000    0.002    0.000 query.py:2000(is_nullable)
       39    0.000    0.000    0.002    0.000 query.py:251(get_compiler)
       58    0.000    0.000    0.002    0.000 lookups.py:80(process_lhs)
       39    0.000    0.000    0.002    0.000 base.py:334(convert_query)
     1244    0.002    0.000    0.002    0.000 :0(utcoffset)
      850    0.002    0.000    0.002    0.000 query_utils.py:202(select_related_descend)
      119    0.001    0.000    0.002    0.000 query.py:704(table_alias)
      678    0.002    0.000    0.002    0.000 :0(copy)
      509    0.002    0.000    0.002    0.000 tree.py:21(__init__)
       78    0.001    0.000    0.002    0.000 compiler.py:756(<listcomp>)
      223    0.001    0.000    0.002    0.000 tree.py:32(_new_instance)
      157    0.001    0.000    0.002    0.000 utils.py:24(__getattr__)
       85    0.001    0.000    0.002    0.000 client.py:1516(_encode)
       56    0.001    0.000    0.002    0.000 lookups.py:70(get_prep_lookup)
        7    0.000    0.000    0.002    0.000 lookups.py:349(process_rhs)
       85    0.001    0.000    0.002    0.000 lzma.py:20(decompress)
       68    0.001    0.000    0.002    0.000 __init__.py:448(__init__)
       39    0.001    0.000    0.002    0.000 query.py:791(reset_refcounts)
      105    0.001    0.000    0.001    0.000 compiler.py:802(deferred_to_columns)
        7    0.001    0.000    0.001    0.000 lookups.py:207(get_prep_lookup)
        5    0.000    0.000    0.001    0.000 related_lookups.py:59(as_sql)
       39    0.001    0.000    0.001    0.000 :0(sub)
       10    0.000    0.000    0.001    0.000 reverse_related.py:182(get_path_info)
        2    0.000    0.000    0.001    0.001 lookups.py:239(batch_process_rhs)
       53    0.001    0.000    0.001    0.000 lookups.py:186(get_db_prep_lookup)
      9/5    0.000    0.000    0.001    0.000 expressions.py:198(resolve_expression)
       70    0.001    0.000    0.001    0.000 query.py:1715(add_select_related)
       85    0.001    0.000    0.001    0.000 default.py:507(make_key)
       10    0.000    0.000    0.001    0.000 related.py:1555(get_reverse_path_info)
       10    0.000    0.000    0.001    0.000 related.py:1520(_get_path_info)
      458    0.001    0.000    0.001    0.000 _weakrefset.py:70(__contains__)
       58    0.001    0.000    0.001    0.000 __init__.py:622(db_type)
       21    0.000    0.000    0.001    0.000 query_utils.py:78(__and__)
      438    0.001    0.000    0.001    0.000 :0(update)
       63    0.001    0.000    0.001    0.000 functools.py:356(_make_key)
        7    0.000    0.000    0.001    0.000 related.py:990(db_type)
      612    0.001    0.000    0.001    0.000 expressions.py:136(__init__)
      500    0.001    0.000    0.001    0.000 :0(proxy)
       21    0.000    0.000    0.001    0.000 query_utils.py:66(_combine)
       85    0.001    0.000    0.001    0.000 lzma.py:486(decompress)
       39    0.000    0.000    0.001    0.000 base.py:217(_prepare_cursor)
      612    0.001    0.000    0.001    0.000 expressions.py:240(_output_field_or_none)
      237    0.001    0.000    0.001    0.000 :0(join)
        9    0.000    0.000    0.001    0.000 expressions.py:310(copy)
       89    0.000    0.000    0.001    0.000 __init__.py:962(get_prep_value)
       21    0.000    0.000    0.001    0.000 related.py:655(get_local_related_value)
        7    0.000    0.000    0.001    0.000 __init__.py:950(rel_db_type)
        5    0.000    0.000    0.001    0.000 related_descriptors.py:500(__get__)
       85    0.000    0.000    0.001    0.000 default.py:77(get_client)
       63    0.000    0.000    0.001    0.000 lookups.py:246(<genexpr>)
       85    0.001    0.000    0.001    0.000 __init__.py:98(__getattr__)
       17    0.000    0.000    0.001    0.000 datastructures.py:117(demote)
      133    0.001    0.000    0.001    0.000 <string>:12(__new__)
      134    0.001    0.000    0.001    0.000 _collections_abc.py:438(items)
        7    0.000    0.000    0.001    0.000 base_user.py:67(__init__)
      541    0.001    0.000    0.001    0.000 __init__.py:1089(get_internal_type)
        5    0.000    0.000    0.001    0.000 related_descriptors.py:793(__init__)
        2    0.000    0.000    0.001    0.000 related_lookups.py:116(as_sql)
      438    0.001    0.000    0.001    0.000 __init__.py:677(unique)
       17    0.000    0.000    0.001    0.000 datastructures.py:101(relabeled_clone)
      484    0.001    0.000    0.001    0.000 __init__.py:935(get_internal_type)
        1    0.000    0.000    0.001    0.001 models.py:1253(get_queryset)
      9/5    0.000    0.000    0.001    0.000 expressions.py:216(<listcomp>)
       39    0.000    0.000    0.001    0.000 query.py:1055(db)
        7    0.000    0.000    0.001    0.000 __init__.py:145(__init__)
      117    0.001    0.000    0.001    0.000 query.py:618(deferred_to_data)
      119    0.000    0.000    0.001    0.000 __init__.py:747(get_prep_value)
       61    0.000    0.000    0.001    0.000 lookups.py:231(resolve_expression_parameter)
      266    0.001    0.000    0.001    0.000 options.py:596(get_field)
        1    0.000    0.000    0.001    0.001 models.py:1327(get_queryset)
        1    0.000    0.000    0.001    0.001 models.py:1248(apply_select_related)
       30    0.000    0.000    0.001    0.000 functional.py:14(_curried)
       39    0.000    0.000    0.001    0.000 compiler.py:20(__init__)
      269    0.001    0.000    0.001    0.000 query.py:258(get_meta)
       85    0.000    0.000    0.001    0.000 msgpack.py:14(loads)
      360    0.001    0.000    0.001    0.000 __init__.py:1855(get_internal_type)
      170    0.001    0.000    0.001    0.000 :0(format)
       39    0.000    0.000    0.001    0.000 __init__.py:1257(debug)
       63    0.000    0.000    0.001    0.000 lookups.py:126(contains_aggregate)
        2    0.000    0.000    0.001    0.000 related_lookups.py:100(get_prep_lookup)
       39    0.000    0.000    0.001    0.000 compiler.py:341(get_extra_select)
        1    0.000    0.000    0.001    0.001 query.py:260(__getitem__)
       85    0.000    0.000    0.001    0.000 default.py:59(get_next_client_index)
      224    0.001    0.000    0.001    0.000 related.py:685(<genexpr>)
        1    0.000    0.000    0.001    0.001 models.py:1322(apply_select_related)
      138    0.000    0.000    0.000    0.000 :0(split)
        4    0.000    0.000    0.000    0.000 compiler.py:591(find_ordering_name)
       62    0.000    0.000    0.000    0.000 query.py:1249(<genexpr>)
       39    0.000    0.000    0.000    0.000 :0(execute)
       21    0.000    0.000    0.000    0.000 related.py:647(local_related_fields)
       39    0.000    0.000    0.000    0.000 query.py:59(<listcomp>)
       26    0.000    0.000    0.000    0.000 related.py:661(get_instance_value_for_fields)
      157    0.000    0.000    0.000    0.000 utils.py:70(__exit__)
       39    0.000    0.000    0.000    0.000 utils.py:258(_route_db)
       78    0.000    0.000    0.000    0.000 query.py:1814(get_loaded_field_names)
       63    0.000    0.000    0.000    0.000 functools.py:349(__init__)
        5    0.000    0.000    0.000    0.000 related_lookups.py:44(get_prep_lookup)
      249    0.000    0.000    0.000    0.000 __init__.py:1021(get_internal_type)
       85    0.000    0.000    0.000    0.000 :0(decompress)
      168    0.000    0.000    0.000    0.000 :0(__new__)
       39    0.000    0.000    0.000    0.000 compiler.py:568(get_distinct)
      170    0.000    0.000    0.000    0.000 :0(encode)
       78    0.000    0.000    0.000    0.000 :0(cursor)
       58    0.000    0.000    0.000    0.000 datastructures.py:303(__init__)
       39    0.000    0.000    0.000    0.000 base.py:217(create_cursor)
       10    0.000    0.000    0.000    0.000 reverse_related.py:146(get_joining_columns)
       30    0.000    0.000    0.000    0.000 copyreg.py:87(__newobj__)
       39    0.000    0.000    0.000    0.000 re.py:221(compile)
       39    0.000    0.000    0.000    0.000 __init__.py:1514(isEnabledFor)
       78    0.000    0.000    0.000    0.000 :0(difference)
       39    0.000    0.000    0.000    0.000 :0(fetchone)
      150    0.000    0.000    0.000    0.000 copy.py:125(_copy_with_constructor)
      117    0.000    0.000    0.000    0.000 :0(close)
       39    0.000    0.000    0.000    0.000 datastructures.py:142(as_sql)
       78    0.000    0.000    0.000    0.000 :0(keys)
       10    0.000    0.000    0.000    0.000 related.py:687(get_reverse_joining_columns)
       86    0.000    0.000    0.000    0.000 :0(unpackb)
        5    0.000    0.000    0.000    0.000 expressions.py:1068(as_sqlite)
       39    0.000    0.000    0.000    0.000 base.py:569(make_debug_cursor)
      131    0.000    0.000    0.000    0.000 tree.py:68(__bool__)
       63    0.000    0.000    0.000    0.000 query.py:1056(check_related_objects)
       10    0.000    0.000    0.000    0.000 pipes.py:285(process_next_start)
        2    0.000    0.000    0.000    0.000 lookups.py:42(batch_process_rhs)
       68    0.000    0.000    0.000    0.000 query.py:738(promote_joins)
       85    0.000    0.000    0.000    0.000 :0(hexdigest)
        1    0.000    0.000    0.000    0.000 query.py:772(all)
    78/12    0.000    0.000    0.000    0.000 compiler.py:216(get_select_from_parent)
       66    0.000    0.000    0.000    0.000 query.py:1706(<listcomp>)
       63    0.000    0.000    0.000    0.000 :0(union)
       84    0.000    0.000    0.000    0.000 :0(_count_elements)
        5    0.000    0.000    0.000    0.000 related.py:658(get_foreign_related_value)
        5    0.000    0.000    0.000    0.000 expressions.py:1052(as_sql)
      134    0.000    0.000    0.000    0.000 _collections_abc.py:456(__init__)
      157    0.000    0.000    0.000    0.000 utils.py:67(__enter__)
       39    0.000    0.000    0.000    0.000 :0(all)
       39    0.000    0.000    0.000    0.000 base.py:529(validate_thread_sharing)
       78    0.000    0.000    0.000    0.000 :0(time)
      131    0.000    0.000    0.000    0.000 query.py:734(unref_alias)
       85    0.000    0.000    0.000    0.000 :0(openssl_sha224)
        1    0.000    0.000    0.000    0.000 recommend.py:256(_get_score_mapper_dict)
       93    0.000    0.000    0.000    0.000 :0(issubclass)
       39    0.000    0.000    0.000    0.000 operations.py:309(compiler)
       85    0.000    0.000    0.000    0.000 base.py:27(default_key_func)
       39    0.000    0.000    0.000    0.000 compiler.py:343(<listcomp>)
        2    0.000    0.000    0.000    0.000 lookups.py:194(<listcomp>)
        4    0.000    0.000    0.000    0.000 compiler.py:623(_setup_joins)
       11    0.000    0.000    0.000    0.000 __init__.py:1097(get_prep_value)
       16    0.000    0.000    0.000    0.000 __init__.py:1039(get_prep_value)
       66    0.000    0.000    0.000    0.000 :0(index)
        2    0.000    0.000    0.000    0.000 related_lookups.py:23(get_normalized_value)
       26    0.000    0.000    0.000    0.000 manager.py:23(__new__)
      105    0.000    0.000    0.000    0.000 query.py:1590(can_filter)
       15    0.000    0.000    0.000    0.000 related.py:1571(_get_m2m_attr)
       85    0.000    0.000    0.000    0.000 __init__.py:67(__getitem__)
       39    0.000    0.000    0.000    0.000 compiler.py:837(<listcomp>)
        8    0.000    0.000    0.000    0.000 random.py:214(randint)
       95    0.000    0.000    0.000    0.000 query.py:730(ref_alias)
       21    0.000    0.000    0.000    0.000 lookups.py:105(rhs_is_direct_value)
        6    0.000    0.000    0.000    0.000 query_utils.py:81(__invert__)
       31    0.000    0.000    0.000    0.000 query.py:1661(add_ordering)
       39    0.000    0.000    0.000    0.000 compiler.py:53(get_group_by)
       15    0.000    0.000    0.000    0.000 related.py:1589(_get_m2m_reverse_attr)
      120    0.000    0.000    0.000    0.000 __init__.py:1375(get_internal_type)
       79    0.000    0.000    0.000    0.000 utils.py:96(__call__)
        1    0.000    0.000    0.000    0.000 recommend.py:168(_sort_combined_recommendations)
       91    0.000    0.000    0.000    0.000 :0(setdefault)
       78    0.000    0.000    0.000    0.000 compiler.py:35(<genexpr>)
       87    0.000    0.000    0.000    0.000 recommend_utils.py:107(next)
       30    0.000    0.000    0.000    0.000 :0(__reduce_ex__)
       10    0.000    0.000    0.000    0.000 related.py:911(get_reverse_path_info)
       40    0.000    0.000    0.000    0.000 compiler.py:1285(<listcomp>)
        8    0.000    0.000    0.000    0.000 random.py:170(randrange)
       85    0.000    0.000    0.000    0.000 cache.py:57(client)
        5    0.000    0.000    0.000    0.000 query.py:219(annotations)
       66    0.000    0.000    0.000    0.000 __init__.py:735(get_cache_name)
       39    0.000    0.000    0.000    0.000 re.py:277(_compile)
       13    0.000    0.000    0.000    0.000 manager.py:184(__get__)
       11    0.000    0.000    0.000    0.000 datastructures.py:308(__getitem__)
       89    0.000    0.000    0.000    0.000 __init__.py:956(get_db_prep_value)
        1    0.000    0.000    0.000    0.000 recommend_utils.py:174(get_top_n_score)
        1    0.000    0.000    0.000    0.000 expressions.py:470(resolve_expression)
       51    0.000    0.000    0.000    0.000 lookups.py:175(get_rhs_op)
        1    0.000    0.000    0.000    0.000 query.py:1461(resolve_ref)
       21    0.000    0.000    0.000    0.000 related.py:371(<dictcomp>)
       85    0.000    0.000    0.000    0.000 util.py:15(__init__)
       10    0.000    0.000    0.000    0.000 related.py:643(reverse_related_fields)
       66    0.000    0.000    0.000    0.000 compiler.py:708(get_related_klass_infos)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
       15    0.000    0.000    0.000    0.000 reverse_related.py:179(get_cache_name)
       74    0.000    0.000    0.000    0.000 related.py:705(get_extra_restriction)
       48    0.000    0.000    0.000    0.000 query.py:1898(annotation_select)
       39    0.000    0.000    0.000    0.000 __init__.py:1500(getEffectiveLevel)
        8    0.000    0.000    0.000    0.000 random.py:220(_randbelow)
        4    0.000    0.000    0.000    0.000 pipeline.py:17(__init__)
        4    0.000    0.000    0.000    0.000 compiler.py:621(<listcomp>)
       63    0.000    0.000    0.000    0.000 :0(hash)
       63    0.000    0.000    0.000    0.000 functools.py:353(__hash__)
       30    0.000    0.000    0.000    0.000 :0(id)
       39    0.000    0.000    0.000    0.000 base.py:142(queries_logged)
       58    0.000    0.000    0.000    0.000 operations.py:237(lookup_cast)
       58    0.000    0.000    0.000    0.000 operations.py:168(field_cast_sql)
       39    0.000    0.000    0.000    0.000 utils.py:18(__init__)
       39    0.000    0.000    0.000    0.000 datastructures.py:138(__init__)
       40    0.000    0.000    0.000    0.000 :0(round)
       39    0.000    0.000    0.000    0.000 query.py:37(__init__)
       46    0.000    0.000    0.000    0.000 query.py:1452(<genexpr>)
       46    0.000    0.000    0.000    0.000 query.py:1453(<genexpr>)
       42    0.000    0.000    0.000    0.000 related.py:649(<genexpr>)
        2    0.000    0.000    0.000    0.000 related.py:965(get_db_prep_value)
       39    0.000    0.000    0.000    0.000 base.py:207(ensure_connection)
        5    0.000    0.000    0.000    0.000 manager.py:29(__init__)
       39    0.000    0.000    0.000    0.000 base.py:445(validate_no_broken_transaction)
       31    0.000    0.000    0.000    0.000 query.py:1686(clear_ordering)
        1    0.000    0.000    0.000    0.000 :0(sorted)
       39    0.000    0.000    0.000    0.000 :0(get_ident)
       11    0.000    0.000    0.000    0.000 __init__.py:1092(to_python)
        4    0.000    0.000    0.000    0.000 pipeline.py:52(set_pipes)
        5    0.000    0.000    0.000    0.000 operations.py:29(check_expression_support)
       23    0.000    0.000    0.000    0.000 :0(issubset)
        1    0.000    0.000    0.000    0.000 recommend.py:140(_combine_recommendations)
        1    0.000    0.000    0.000    0.000 recommend_utils.py:190(<listcomp>)
       10    0.000    0.000    0.000    0.000 base.py:641(_get_pk_val)
       15    0.000    0.000    0.000    0.000 reverse_related.py:162(get_accessor_name)
       30    0.000    0.000    0.000    0.000 __init__.py:1783(get_internal_type)
       24    0.000    0.000    0.000    0.000 query.py:1457(<genexpr>)
       21    0.000    0.000    0.000    0.000 base.py:453(_default_manager)
        5    0.000    0.000    0.000    0.000 options.py:649(get_ancestor_link)
        2    0.000    0.000    0.000    0.000 query.py:1045(check_query_object_type)
        5    0.000    0.000    0.000    0.000 :0(search)
        5    0.000    0.000    0.000    0.000 manager.py:124(_set_creation_counter)
       23    0.000    0.000    0.000    0.000 __init__.py:755(get_db_prep_value)
       12    0.000    0.000    0.000    0.000 related.py:441(related_query_name)
       21    0.000    0.000    0.000    0.000 base.py:449(_base_manager)
        6    0.000    0.000    0.000    0.000 expressions.py:184(contains_aggregate)
       21    0.000    0.000    0.000    0.000 related.py:690(get_extra_descriptor_filter)
       13    0.000    0.000    0.000    0.000 options.py:343(swapped)
        5    0.000    0.000    0.000    0.000 reverse_related.py:149(get_extra_restriction)
        5    0.000    0.000    0.000    0.000 expressions.py:1032(__init__)
       12    0.000    0.000    0.000    0.000 query.py:1456(<dictcomp>)
        4    0.000    0.000    0.000    0.000 pipes.py:261(__init__)
       16    0.000    0.000    0.000    0.000 __init__.py:1024(to_python)
       13    0.000    0.000    0.000    0.000 :0(getrandbits)
        5    0.000    0.000    0.000    0.000 query.py:1168(_add_hints)
       11    0.000    0.000    0.000    0.000 :0(__getitem__)
       10    0.000    0.000    0.000    0.000 related.py:645(<listcomp>)
        4    0.000    0.000    0.000    0.000 recommend_utils.py:102(__init__)
        8    0.000    0.000    0.000    0.000 pipes.py:18(__init__)
        8    0.000    0.000    0.000    0.000 query.py:2030(get_order_dir)
        4    0.000    0.000    0.000    0.000 expressions.py:146(set_source_expressions)
        4    0.000    0.000    0.000    0.000 pipeline.py:34(set_starts)
        1    0.000    0.000    0.000    0.000 model_access.py:346(<listcomp>)
        3    0.000    0.000    0.000    0.000 pipes.py:330(__init__)
        2    0.000    0.000    0.000    0.000 query_utils.py:252(check_rel_lookup_compatibility)
        8    0.000    0.000    0.000    0.000 :0(bit_length)
        5    0.000    0.000    0.000    0.000 :0(group)
        9    0.000    0.000    0.000    0.000 expressions.py:143(get_source_expressions)
        7    0.000    0.000    0.000    0.000 __init__.py:738(get_internal_type)
        1    0.000    0.000    0.000    0.000 __init__.py:1849(get_prep_value)
        1    0.000    0.000    0.000    0.000 model_access.py:364(<listcomp>)
        1    0.000    0.000    0.000    0.000 recommend.py:177(<dictcomp>)
        8    0.000    0.000    0.000    0.000 pipes.py:30(set_starts)
        1    0.000    0.000    0.000    0.000 expressions.py:476(desc)
        6    0.000    0.000    0.000    0.000 expressions.py:1049(get_source_expressions)
        1    0.000    0.000    0.000    0.000 query.py:1042(ordered)
        7    0.000    0.000    0.000    0.000 operations.py:245(max_in_list_size)
        5    0.000    0.000    0.000    0.000 models.py:891(<listcomp>)
        5    0.000    0.000    0.000    0.000 :0(rstrip)
        6    0.000    0.000    0.000    0.000 tree.py:127(negate)
        5    0.000    0.000    0.000    0.000 related_lookups.py:47(<listcomp>)
        5    0.000    0.000    0.000    0.000 expressions.py:1046(set_source_expressions)
        5    0.000    0.000    0.000    0.000 related_lookups.py:56(<listcomp>)
        5    0.000    0.000    0.000    0.000 query.py:1122(_next_is_sticky)
        1    0.000    0.000    0.000    0.000 utils.py:14(str_to_bool)
        1    0.000    0.000    0.000    0.000 recommend.py:176(<listcomp>)
        1    0.000    0.000    0.000    0.000 pipes.py:279(__init__)
        2    0.000    0.000    0.000    0.000 query_utils.py:259(check)
        2    0.000    0.000    0.000    0.000 lookups.py:374(get_rhs_op)
        2    0.000    0.000    0.000    0.000 :0(from_iterable)
        1    0.000    0.000    0.000    0.000 recommend.py:87(__init__)
        1    0.000    0.000    0.000    0.000 query.py:1560(set_limits)
        1    0.000    0.000    0.000    0.000 model_access.py:329(<listcomp>)
        1    0.000    0.000    0.000    0.000 recommend.py:245(<listcomp>)
        1    0.000    0.000    0.000    0.000 __init__.py:2333(get_internal_type)
        1    0.000    0.000    0.000    0.000 :0(insert)
        1    0.000    0.000    0.000    0.000 expressions.py:460(__init__)
        1    0.000    0.000    0.000    0.000 __init__.py:2073(get_internal_type)
        0    0.000             0.000          profile:0(profiler)


Out[7]:
<pstats.Stats at 0x7f17492b7588>

In [ ]: