Skip to content

Commit 48d9632

Browse files
chore: refactor ranges, add more tests
Signed-off-by: Henry Gressmann <[email protected]>
1 parent efaed52 commit 48d9632

File tree

24 files changed

+469
-225
lines changed

24 files changed

+469
-225
lines changed

.github/workflows/test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ on:
1212
workflow_dispatch:
1313

1414
jobs:
15+
build-web:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: oven-sh/setup-bun@v2
20+
with:
21+
bun-version: latest
22+
- name: Build web project
23+
run: |
24+
bun install
25+
bun run build
26+
working-directory: ./web
27+
- name: Run tests
28+
run: bun test
29+
working-directory: ./web
30+
- name: Run typecheck
31+
run: bun typecheck
32+
working-directory: ./web
33+
1534
test:
1635
strategy:
1736
matrix:

Cargo.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/core/reports.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@ use crate::utils::duckdb::{repeat_vars, ParamVec};
66
use duckdb::params_from_iter;
77
use eyre::{bail, Result};
88
use poem_openapi::{Enum, Object};
9-
use time::OffsetDateTime;
109

1110
#[derive(Object)]
1211
pub struct DateRange {
13-
pub start: u64,
14-
pub end: u64,
12+
pub start: time::OffsetDateTime,
13+
pub end: time::OffsetDateTime,
1514
}
1615

1716
impl DateRange {
18-
pub fn start(&self) -> OffsetDateTime {
19-
OffsetDateTime::from_unix_timestamp((self.start / 1000) as i64).unwrap_or(OffsetDateTime::UNIX_EPOCH)
20-
}
21-
22-
pub fn end(&self) -> OffsetDateTime {
23-
OffsetDateTime::from_unix_timestamp((self.end / 1000) as i64).unwrap_or(OffsetDateTime::UNIX_EPOCH)
24-
}
25-
2617
pub fn prev(&self) -> DateRange {
2718
let duration = self.end - self.start;
2819
DateRange { start: self.start - duration, end: self.start }
@@ -241,14 +232,14 @@ pub fn overall_report(
241232

242233
let entity_vars = repeat_vars(entities.len());
243234

244-
params.push(range.start());
245-
params.push(range.end());
235+
params.push(range.start);
236+
params.push(range.end);
246237
params.push(data_points);
247238
params.push(data_points);
248239
params.push(event);
249240
params.extend(entities);
250241
params.extend_from_params(filters_params);
251-
params.push(range.end());
242+
params.push(range.end);
252243

253244
let query = format!("--sql
254245
with
@@ -335,8 +326,8 @@ pub fn overall_stats(
335326
let metric_unique_visitors = metric_sql(Metric::UniqueVisitors);
336327
let metric_avg_views_per_visitor = metric_sql(Metric::AvgViewsPerSession);
337328

338-
params.push(range.start());
339-
params.push(range.end());
329+
params.push(range.start);
330+
params.push(range.end);
340331
params.push(event);
341332
params.extend(entities);
342333
params.extend_from_params(filters_params);
@@ -418,8 +409,8 @@ pub fn dimension_report(
418409
Dimension::UtmTerm => ("utm_term", "utm_term"),
419410
};
420411

421-
params.push(range.start());
422-
params.push(range.end());
412+
params.push(range.start);
413+
params.push(range.end);
423414
params.push(event);
424415
params.extend(entities);
425416
params.extend_from_params(filters_params);

src/utils/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
web::SessionUser,
44
};
55

6-
pub const MAX_DATAPOINTS: u32 = 100;
6+
pub const MAX_DATAPOINTS: u32 = 2000;
77

88
pub fn is_valid_id(id: &str) -> bool {
99
id.chars().all(|c| c.is_alphanumeric() || c == '-' || c == '_' || c == '.' || c == ':')

web/bun.lockb

352 Bytes
Binary file not shown.

web/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@radix-ui/react-accordion": "^1.2.1",
1919
"@radix-ui/react-dialog": "^1.1.2",
2020
"@radix-ui/react-tabs": "^1.1.1",
21-
"@tanstack/react-query": "^5.60.5",
21+
"@tanstack/react-query": "^5.61.0",
2222
"@uidotdev/usehooks": "^2.4.1",
2323
"date-fns": "^4.1.0",
2424
"fets": "^0.8.4",
@@ -29,16 +29,16 @@
2929
"react": "^18.3.1",
3030
"react-dom": "^18.3.1",
3131
"react-simple-maps": "^3.0.0",
32-
"react-tag-autocomplete": "^7.3.0",
32+
"react-tag-autocomplete": "^7.4.0",
3333
"react-tooltip": "^5.28.0"
3434
},
3535
"devDependencies": {
3636
"@biomejs/biome": "1.9.4",
37+
"@types/bun": "^1.1.13",
3738
"@types/react": "^18.3.12",
3839
"@types/react-dom": "^18.3.1",
3940
"@types/react-simple-maps": "^3.0.6",
4041
"astro": "^4.16.13",
41-
"bun-types": "^1.1.34",
4242
"rollup-plugin-license": "^3.5.3",
4343
"typescript": "^5.6.3"
4444
},

0 commit comments

Comments
 (0)