Exploring SQL activity of new dashboardΒΆ

See 2021-06-15.

>>> from lino import startup
>>> startup('lino_book.projects.noi1r.settings')
>>> from lino.api.doctest import *

During startup there were two SQL queries:

>>> show_sql_queries()  
SELECT excerpts_excerpttype.id, excerpts_excerpttype.name, excerpts_excerpttype.build_method, excerpts_excerpttype.template, excerpts_excerpttype.attach_to_email, excerpts_excerpttype.email_template, excerpts_excerpttype.certifying, excerpts_excerpttype.remark, excerpts_excerpttype.body_template, excerpts_excerpttype.content_type_id, excerpts_excerpttype.primary, excerpts_excerpttype.backward_compat, excerpts_excerpttype.print_recipient, excerpts_excerpttype.print_directly, excerpts_excerpttype.shortcut, excerpts_excerpttype.name_de, excerpts_excerpttype.name_fr FROM excerpts_excerpttype ORDER BY excerpts_excerpttype.id ASC
SELECT django_content_type.id, django_content_type.app_label, django_content_type.model FROM django_content_type WHERE django_content_type.id = ...
SELECT django_content_type.id, django_content_type.app_label, django_content_type.model FROM django_content_type WHERE django_content_type.id = ...

Now we do a single request to Tickets. And look at all the SQL that poor Django must do in order to return a single row.

>>> reset_sql_queries()
>>> ses = rt.login('robin')
>>> test_client.force_login(ses.get_user())
>>> r = test_client.get('/')
>>> show_sql_summary()
================ =========== =======
 table            stmt_type   count
---------------- ----------- -------
                  UNKNOWN     1
                  UPDATE      1
 django_session   SELECT      1
 users_user       SELECT      1
================ =========== =======
>>> reset_sql_queries()
>>> ses.show('system.Dashboard')
... 
Quick links:
...
Hi, Robin Rood!
...
Jean commented on **Front-end team**:Some plain text.
>>> show_sql_summary()
... # tickets_ticket & users_user queries are more then expected probably because of multiple tries when there's a connection error from elasticsearch's side.
... 
========================= =========== =======
 table                     stmt_type   count
------------------------- ----------- -------
 cal_event                 SELECT      10
 cal_eventtype             SELECT      1
 cal_task                  SELECT      1
 calview_dailyplannerrow   SELECT      1
 comments_comment          SELECT      16
 dashboard_widget          SELECT      1
 django_content_type       SELECT      2
 groups_group              SELECT      18
 groups_membership         SELECT      41
 ledger_accountingperiod   SELECT      2
 ledger_fiscalyear         SELECT      2
 ledger_journal            SELECT      4
 ledger_ledgerinfo         SELECT      3
 notify_message            SELECT      3
 orders_order              SELECT      5
 sales_vatproductinvoice   SELECT      1
 subquery                  SELECT      1
 system_siteconfig         SELECT      4
 tickets_site              SELECT      45
 tickets_ticket            SELECT      58
 tickets_tickettype        SELECT      15
 users_user                SELECT      115
 working_session           SELECT      52
========================= =========== =======
>>> show_sql_queries()
... 

>> r = test_client.get('/api/system/Dashboard') >> print(r)

>> r = demo_get('robin','api/tickets/Tickets', fmt='json', limit=1) >> res = test_client.get('/api/tickets/Tickets?fmt=json&limit=1') >> res = check_json_result(res) >> rmu(res.keys()) ['count', 'rows', 'no_data_text', 'success', 'title', 'param_values'] >> len(res['rows']) 1