go-u8views
go-u8views copied to clipboard
GitHub-profile views tracker: displaying monthly view statistics
u8views.com
Profile views counter
Development
Start local development session
cp .local.env .env
make env-up
make migrate-all-reset
make postgres-fixtures
make postgres-fixtures-count
# and
# make postgres-fixtures-clear
Run after code changes
make env-up
End development session
make env-down
# or
# make env-down-with-clear
Benchmark (PC) Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
BENCHTIME=100x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService-12 100 627990 ns/op 5033 B/op 80 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 0.088s
BENCHTIME=1000x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService-12 1000 449478 ns/op 4124 B/op 72 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 0.471s
BENCHTIME=10000x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService-12 10000 546875 ns/op 4885 B/op 81 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 5.492s
Benchmark (vultr.com VPS 1024.00 MB High Frequency) Intel Core Processor (Skylake, IBRS)
BENCHTIME=100x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService 100 2275173 ns/op 1562 B/op 43 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 0.360s
BENCHTIME=1000x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService 1000 2121516 ns/op 1571 B/op 44 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 2.153s
BENCHTIME=10000x make bench
BenchmarkProfileStatsService
BenchmarkProfileStatsService 10000 2153319 ns/op 1574 B/op 44 allocs/op
PASS
ok github.com/u8views/go-u8views/internal/tests 21.566s
Database schema templates
Database schema
SQL
SELECT user_id, SUM(count), COUNT(*)
FROM profile_hourly_views_stats
GROUP BY user_id
ORDER BY SUM(count) DESC
LIMIT 100;
SELECT g.time::TIMESTAMP
FROM (
SELECT time::TIMESTAMP
FROM generate_series(
(DATE_TRUNC('DAY', NOW()) - INTERVAL '1 MONTH')::TIMESTAMP,
(DATE_TRUNC('DAY', NOW()))::TIMESTAMP,
'1 DAY'::INTERVAL
) AS time
) AS g;
Stats
SELECT DATE_TRUNC('MONTH', time) AS month,
COUNT(*) AS views,
COUNT(DISTINCT (user_id)) AS users
FROM profile_hourly_views_stats
GROUP BY 1
ORDER BY 1;
Month | Views | Users |
---|---|---|
2023-01-01 | 15 | 3 |
2023-02-01 | 438 | 18 |
2023-03-01 | 951 | 32 |
2023-04-01 | 1110 | 36 |
2023-05-01 | 2191 | 43 |
2023-06-01 | 3433 | 57 |
2023-07-01 | 3331 | 54 |
2023-08-01 | 4539 | 69 |
2023-09-01 | 4519 | 77 |
2023-10-01 | 4473 | 78 |
2023-11-01 | 4919 | 96 |
2023-12-01 | 5525 | 115 |
2024-01-01 | 11185 | 232 |
2024-02-01 | 11348 | 245 |
2024-03-01 | 7334 | 249 |