Skip to content

Commit 3c6dc00

Browse files
committed
don’t update stats from logged-in users
1 parent 4e16cbb commit 3c6dc00

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

Sources/UnidocPages/Tours/ServerTour.Stats.ByType.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,24 @@ extension ServerTour.Stats
66
public
77
var siteMap:Int
88
public
9-
var restricted:Int
10-
public
119
var query:Int
1210
public
1311
var other:Int
1412

1513
@inlinable public
1614
init(siteMap:Int = 0,
17-
restricted:Int = 0,
1815
query:Int = 0,
1916
other:Int = 0)
2017
{
2118
self.siteMap = siteMap
22-
self.restricted = restricted
2319
self.query = query
2420
self.other = other
2521
}
2622
}
2723
}
2824
extension ServerTour.Stats.ByType
2925
{
30-
/// The total count, except for the ``restricted`` type.
26+
/// The total count.
3127
@inlinable public
3228
var total:Int
3329
{

Sources/UnidocServer/RestrictedOperation.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ protocol RestrictedOperation:InteractiveOperation
1111
func load(from state:Server.State) async throws -> ServerResponse?
1212
}
1313
extension RestrictedOperation
14-
{
15-
var statisticalType:WritableKeyPath<ServerTour.Stats.ByType, Int>
16-
{
17-
\.restricted
18-
}
19-
}
20-
extension RestrictedOperation
2114
{
2215
static
2316
func admit(_ role:Account.Role) -> Bool

Sources/UnidocServer/Server/Server.State.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ extension Server.State
5050
content: .string("not found"),
5151
type: .text(.plain, charset: .utf8)))
5252

53-
self.tour.stats.requests[keyPath: type] += 1
53+
// Don’t increment stats from administrators,
54+
// they will really skew the results.
55+
if case nil = request.cookies.session
56+
{
57+
self.tour.stats.requests[keyPath: type] += 1
58+
self.tour.stats.bytes[keyPath: type] += response.size
5459

55-
let status:WritableKeyPath<ServerTour.Stats.ByStatus, Int> =
56-
response.statisticalStatus
60+
let status:WritableKeyPath<ServerTour.Stats.ByStatus, Int> =
61+
response.statisticalStatus
5762

58-
// Don’t count visits to the admin tools.
59-
if type != \.restricted
60-
{
6163
self.tour.stats.responses[keyPath: status] += 1
62-
self.tour.stats.bytes[keyPath: type] += response.size
6364
}
6465

6566
request.promise.succeed(response)

0 commit comments

Comments
 (0)