Skip to content

Commit e2b0f63

Browse files
committed
Count hits by source file
1 parent a8f2a79 commit e2b0f63

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

server/src/main/kotlin/at/yawk/javabrowser/server/BaseHandler.kt

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import io.undertow.server.HttpServerExchange
1212
import io.undertow.util.StatusCodes
1313
import org.skife.jdbi.v2.DBI
1414
import org.skife.jdbi.v2.Handle
15+
import java.time.ZoneOffset
16+
import java.time.ZonedDateTime
17+
import java.time.temporal.ChronoUnit
1518

1619
/**
1720
* @author yawkat
@@ -92,6 +95,13 @@ class BaseHandler(private val dbi: DBI,
9295
throw HttpException(StatusCodes.NOT_FOUND, "No such source file")
9396
}
9497

98+
// increment hit counter for this time bin
99+
val timestamp = ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.HOURS)
100+
conn.update("insert into hits (timestamp, sourceFile, artifactId, hits) values (?, ?, ?, 1) on conflict (timestamp, sourceFile, artifactId) do update set hits = hits.hits + 1",
101+
timestamp.toLocalDateTime(),
102+
sourceFilePath,
103+
artifactPath.id)
104+
95105
val alternatives = ArrayList<SourceFileView.Alternative>()
96106
fun tryExactMatch(path: String) {
97107
conn.createQuery("select artifactId, path from sourceFiles where path = ?")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create table hits
2+
(
3+
-- UTC timestamp of this hit counter. Resolution is application-defined, and may be multiple hours.
4+
timestamp timestamp not null,
5+
sourceFile varchar not null,
6+
artifactId varchar not null,
7+
hits int8 not null,
8+
9+
primary key (timestamp, sourceFile, artifactId)
10+
);

0 commit comments

Comments
 (0)