Compare commits

...

3 Commits

Author SHA1 Message Date
SoniEx2 105164e661 Sort(?) correctly(?) 2019-04-19 22:32:15 -03:00
SoniEx2 429d3d5b30 Index repo_history by URL 2019-04-19 16:47:32 -03:00
SoniEx2 ef60898514 Tweak sorting 2019-04-19 16:42:59 -03:00
1 changed files with 10 additions and 2 deletions

View File

@ -87,6 +87,7 @@ def initdb():
c.execute('''CREATE TABLE repos (url TEXT PRIMARY KEY, active INT)''') c.execute('''CREATE TABLE repos (url TEXT PRIMARY KEY, active INT)''')
c.execute('''CREATE INDEX active_key ON repos (active)''') c.execute('''CREATE INDEX active_key ON repos (active)''')
c.execute('''CREATE TABLE repo_history (entry INTEGER PRIMARY KEY ASC AUTOINCREMENT, url TEXT, count INTEGER, head_commit TEXT)''') c.execute('''CREATE TABLE repo_history (entry INTEGER PRIMARY KEY ASC AUTOINCREMENT, url TEXT, count INTEGER, head_commit TEXT)''')
c.execute('''CREATE INDEX url_key ON repo_history (url)''')
c.execute('''CREATE TABLE config (git_commit TEXT, project_title TEXT)''') c.execute('''CREATE TABLE config (git_commit TEXT, project_title TEXT)''')
c.execute('''INSERT INTO config VALUES ('', '')''') c.execute('''INSERT INTO config VALUES ('', '')''')
conn.commit() conn.commit()
@ -197,15 +198,22 @@ def cron_target():
(project_commit, project_title) = c.fetchone() (project_commit, project_title) = c.fetchone()
entries = [] entries = []
generate_html = [] generate_html = []
for (url,) in c.execute("""SELECT url FROM repos WHERE active == 1"""): for (e, url,) in c.execute("""SELECT max(e), url FROM (SELECT max(T1.entry) e, T1.url FROM repo_history T1
WHERE (SELECT active FROM repos T2 WHERE url = T1.url)
GROUP BY T1.url
UNION
SELECT null, T3.url FROM repos T3 WHERE active)
GROUP BY url ORDER BY e"""):
result = handle_target(url, project_commit) result = handle_target(url, project_commit)
if result is not None: if result is not None:
count, post_hash, msg = result count, post_hash, msg = result
entries.append((url, count, post_hash)) entries.append((url, count, post_hash))
generate_html.append((url, msg, count)) generate_html.append((url, msg, count))
# sort stuff twice because reasons
entries.sort(key=lambda x: x[1], reverse=True)
generate_html.sort(key=lambda x: x[2], reverse=True)
c.executemany('''INSERT INTO repo_history VALUES (NULL, ?, ?, ?)''', entries) c.executemany('''INSERT INTO repo_history VALUES (NULL, ?, ?, ?)''', entries)
conn.commit() conn.commit()
generate_html.sort(key=lambda x: x[2]) # sort by count
html_entries = [] html_entries = []
for (url, msg, count) in generate_html: for (url, msg, count) in generate_html:
history = c.execute('''SELECT count FROM repo_history WHERE url == ? ORDER BY entry ASC''', (url,)).fetchall() history = c.execute('''SELECT count FROM repo_history WHERE url == ? ORDER BY entry ASC''', (url,)).fetchall()