harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
36 stars 30 forks source link

Make Matomo usage reporting async #1996

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

Something I should've done a long time ago for @cath9 but fortunately for her now it was annoying me, so I'm improving this.

In the H2O reporting dashboard, high-level stats from Matomo were being fetched synchronously during the request cycle, which made the dashboard page load slowly. For awhile I was considering having the stats fetched and cached via a recurring celery job, but this is simpler, if more ridiculous.

Now the page loads instantly, which gives you immediate access to the Django-side reports, while the Matomo reporting is fetched async and pops in after a few seconds.

This involved writing some wee little Django scaffolding for the endpoint, and porting the Django template code to JS which modifies the DOM once the response comes back. There are also a few mechanical changes to make the Matomo results pickleable; before they could be Django model instances.

Two small functional changes:

lizadaly commented 1 year ago

Got some test work to do here, re-drafting.

codecov-commenter commented 1 year ago

Codecov Report

Merging #1996 (7b36d67) into develop (e62aa6b) will increase coverage by 0.00%. The diff coverage is 81.57%.

@@           Coverage Diff            @@
##           develop    #1996   +/-   ##
========================================
  Coverage    76.92%   76.93%           
========================================
  Files           60       62    +2     
  Lines         6839     6871   +32     
========================================
+ Hits          5261     5286   +25     
- Misses        1578     1585    +7     
Impacted Files Coverage Δ
web/main/urls.py 100.00% <ø> (ø)
web/reporting/admin/usage_dashboard.py 100.00% <ø> (ø)
web/reporting/views.py 64.28% <64.28%> (ø)
web/reporting/matomo.py 83.33% <89.47%> (+0.61%) :arrow_up:
web/main/test/test_permissions.py 97.16% <100.00%> (+0.05%) :arrow_up:
web/reporting/urls.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.