Skip to content

Commit a681f33

Browse files
committed
step 4 done.
1 parent a8c92b0 commit a681f33

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

page_analyzer/app.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,25 @@ def urls():
4949
cur = conn.cursor()
5050
cur.execute('SELECT * FROM urls ORDER BY created_at DESC')
5151
urls = cur.fetchall()
52-
cur.execute('SELECT created_at FROM url_checks ORDER BY created_at DESC')
53-
checks = cur.fetchall()
52+
53+
cur.execute('''
54+
SELECT u.id, u.name, u.created_at,
55+
uc.status_code, uc.created_at AS last_check
56+
FROM urls u
57+
LEFT JOIN url_checks uc ON u.id = uc.url_id
58+
WHERE uc.created_at = (
59+
SELECT MAX(created_at)
60+
FROM url_checks
61+
WHERE url_id = u.id
62+
)
63+
ORDER BY u.created_at DESC
64+
''')
65+
urls = cur.fetchall()
66+
5467
cur.close()
5568
conn.close()
5669

57-
return render_template('urls.html', urls=urls, checks=checks)
70+
return render_template('urls.html', urls=urls)
5871

5972

6073
@app.route('/urls/<int:url_id>', methods=['GET'])

0 commit comments

Comments
 (0)