: nply/minci

commit 5cea413a2e2cbb3f38eede514acf088cd0c37150
parent 18a3e4ccf03a3c3a8356bcf806b9153586d838b4
Author: kristapsdz <kristaps@bsd.lv>
Date: Wed, 11 Mar 2020 21:44:57 +0000

Instead of showing the last n reports, group them and show the last report
for a given project from a given machine class.
2 files changed, 23 insertions(+), 5 deletions(-)
M
db.ort
|
11
++++++++---
M
main.c
|
17
+++++++++++++++--
diff --git a/db.ort b/db.ort
@@ -65,7 +65,7 @@ struct report {
 	field env epoch
 		comment "When the repository has been cloned/updated (ge
 			 start or zero on failure.";
-	field depend epoch;
+	field depend epoch
 		comment "When dependencies have been checked (ge env or
 			 equal or zero on failure or env failure).";
 	field build epoch

@@ -97,18 +97,23 @@ struct report {
 		comment "Output of uname -s.";
 	field unamev text limit le 128
 		comment "Output of uname -v.";
+	field unamehash text limit eq 32
+		comment "Hash of uname[mnrsv].  This is used to quickly
+			 establish a kind of machine identity.";
+
 	field id int rowid;
 
 	insert;
 
-	iterate: limit 50 name last order ctime desc;
 	iterate project.name: limit 50 name lastname order ctime desc;
 	iterate ctime ge, ctime le: limit 50 name lastdate order ctime desc;
 
+	iterate: name dash order projectid,ctime desc grouprow unamehash maxrow ctime;
+
 	search id: name byid;
 
 	roles consumer {
-		iterate last;
+		iterate dash;
 		iterate lastdate;
 		iterate lastname;
 		noexport userid;
diff --git a/main.c b/main.c
@@ -483,7 +483,7 @@ get_last(struct kreq *r)
 			kpd->parsed.i, /* ctime ge */
 			kpd->parsed.i + 86400); /* ctime le */
 	else
-		db_report_iterate_last(r->arg, 
+		db_report_iterate_dash(r->arg, 
 			get_html_last_report, &req);
 
 	khtml_closeelem(&req.html, 1); /* table */

@@ -525,6 +525,7 @@ post(struct kreq *r)
 	MD5_CTX		 ctx;
 	char		*buf = NULL;
 	char		 digest[MD5_DIGEST_STRING_LENGTH],
+			 unamedigest[MD5_DIGEST_STRING_LENGTH],
 			 logdigest[MD5_DIGEST_STRING_LENGTH];
 
 	/* 

@@ -676,6 +677,8 @@ post(struct kreq *r)
 	MD5Init(&ctx);
 	MD5Update(&ctx, buf, sz);
 	MD5End(&ctx, digest);
+	free(buf);
+	buf = NULL;
 
 	if (strcasecmp(digest, sig->parsed.s)) {
 		kutil_warnx(r, NULL, "bad signature");

@@ -683,6 +686,15 @@ post(struct kreq *r)
 		goto out;
 	}
 
+	sz = (size_t)kasprintf(&buf, 
+		"%" PRId64 "|%s|%s|%s|%s|%s",
+		proj->id, kpum->parsed.s, 
+		kpun->parsed.s, kpur->parsed.s, 
+		kpus->parsed.s, kpuv->parsed.s);
+	MD5Init(&ctx);
+	MD5Update(&ctx, buf, sz);
+	MD5End(&ctx, unamedigest);
+
 	/* Insert the record. */
 
 	db_report_insert(r->arg,

@@ -701,7 +713,8 @@ post(struct kreq *r)
 		kpun->parsed.s, /* unamen */
 		kpur->parsed.s, /* unamer */
 		kpus->parsed.s, /* unames */
-		kpuv->parsed.s); /* unamev */
+		kpuv->parsed.s, /* unamev */
+		unamedigest); /* unamehash */
 
 	kutil_info(r, user->email, "log submitted: %s", proj->name);
 	http_open(r, KHTTP_201, KMIME__MAX);