Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c57cc9a

Browse files
committed
Add Post View Geo-IP design doc
Update example request in apis/yaak.rq_mJmyJAYSYR.yaml: change the content field from a string to an empty JSON object and refresh the updatedAt timestamp
1 parent 982cb61 commit c57cc9a

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

‎apis/yaak.rq_mJmyJAYSYR.yaml‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@ type: http_request
22
model: http_request
33
id: rq_mJmyJAYSYR
44
createdAt: 2025年05月01日T00:06:13.497946
5-
updatedAt: 2025-11-06T08:23:29.463646
5+
updatedAt: 2025-11-07T08:45:20.882694
66
workspaceId: wk_udoUbrFfLp
77
folderId: fl_qgXRbryiBV
88
authentication: {}
99
authenticationType: null
1010
body:
11-
text: |-
12-
{
13-
"title": "hamza",
14-
"content": "heeeaasdaee",
15-
"slug": "12aaaaaa",
16-
"category_id": 17,
17-
"tag_ids": [0,1,2,3,4,11,28,36,63]
18-
}
11+
text: "{\n \"title\": \"hamza\",\n \"content\": {\n \n },\n \"slug\": \"12aaaaaa\",\n \"category_id\": 17,\n \"tag_ids\": [0,1,2,3,4,11,28,36,63]\n}"
1912
bodyType: application/json
2013
description: ''
2114
headers:

‎docs/POST_VIEW_GEO_IP.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Post View Geo-IP Enrichment
2+
3+
This document captures the plan for persisting client IP/user agent info on `POST /post/v1/track_view` and enriching those records asynchronously so future analytics can segment by geography or device.
4+
5+
## Current State
6+
- Handler signature only accepts `(State, AuthSession, Path<post_id>)` and calls `post::Entity::increment_view_count(..., None, None)`.
7+
- Global middleware already attaches `ClientIp` via `ip_config.ip_source.into_extension()` so the resolved IP is available in the request context.
8+
- `post_views` table stores `ip_address` and `user_agent` columns (both `Option<String>`) but they remain `NULL`.
9+
10+
## Proposed Flow
11+
1. **Request Capture**
12+
- Update `track_view` handler to accept `Extension<ClientIp>` (and optionally `TypedHeader<UserAgent>`).
13+
- Extract `ip_string` (respecting forwarded headers) and the user agent header.
14+
- Pass both values into `post::Entity::increment_view_count`.
15+
16+
2. **Persistence Updates**
17+
- Adjust `increment_view_count` signature to accept `ip_address: Option<String>` and `user_agent: Option<String>` (matches current schema).
18+
- Ensure insert into `post_views` writes these fields.
19+
20+
3. **Geo Enrichment Queue**
21+
- Introduce a background job (new `queue::post_view_geo`) that:
22+
- Consumes `post_views` records where `geo_country` (new nullable column) is `NULL`.
23+
- Performs a lookup via MaxMind GeoIP2 or a hosted API.
24+
- Updates the row with `country_code`, `region`, etc.
25+
- Trigger job via:
26+
- Direct enqueue after each tracked view, or
27+
- Cron/worker scanning recent `post_views`.
28+
29+
4. **Analytics Consumption**
30+
- Extend analytics queries to join on enriched columns for country/device breakdowns.
31+
- Optionally expose aggregated endpoints (e.g., `/analytics/v1/post/view-countries`).
32+
33+
## Open Questions
34+
- Which GeoIP provider should we standardize on? (needs env wiring + rate limits)
35+
- Do we need to anonymize IPs (e.g., hash or truncate) for privacy compliance?
36+
- How often do we process the enrichment queue (real-time vs. batch)?
37+
38+
## Next Steps
39+
1. Implement handler + DB changes to start persisting IP/user agent.
40+
2. Add migration for geo columns (`country_code`, `subdivision`, `city`, `lookup_source`, `lookup_status`).
41+
3. Build worker/queue scaffolding (could reuse existing job runner if available).
42+
4. Document env vars + failure handling (timeouts, provider fallbacks).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /