Database is hit during module load

Bug #1422548 reported by Michael Nelson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Software Center Agent
Fix Released
Medium
Natalia Bidart

Bug Description

Steps to reproduce:
 1) Edit your database settings so that there's no valid db (ie. change password)
 2) curl a url which is a simple redirect (ie. does not need database) http://localhost:8000/

Expected result:
 3a) Normal redirect to /dev/

Actual result:
 3b) app tries to access database at module load time.

Normally this wouldn't be a huge issue, but when the database latency is huge, it quickly becomes one.

Recently, the src/clickpackage/middleware.py:SetStoreMiddleware was added, which hits the database: https://pastebin.canonical.com/125726/

If we could instead return a (lazy) query set with the required store, so it only hits the db when used, that would be great.

There's also another point which hits the database unnecessarily, but it's been there for a few months: DepartmentField.__init__(): https://pastebin.canonical.com/125725/ .

With both of these fixed, there are zero database queries for simple redirects or other pages which don't use the database (ie. database is not hit during module load).

It would be great to add a test which ensures we don't add any other database hits during module load.

description: updated
Changed in software-center-agent:
status: New → In Progress
assignee: nobody → Natalia Bidart (nataliabidart)
importance: Undecided → Medium
Changed in software-center-agent:
status: In Progress → Fix Committed
Changed in software-center-agent:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.