2026-02-21 15:48:02 +00:00
|
|
|
from datetime import datetime
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
import time
|
2026-02-21 13:52:20 +00:00
|
|
|
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
from api.metrics import record_db_query
|
2026-02-21 13:52:20 +00:00
|
|
|
from models.decision import ListingDecision
|
|
|
|
|
from sqlalchemy import Engine
|
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DecisionRepository:
|
|
|
|
|
engine: Engine
|
|
|
|
|
|
|
|
|
|
def __init__(self, engine: Engine) -> None:
|
|
|
|
|
self.engine = engine
|
|
|
|
|
|
|
|
|
|
def upsert_decision(
|
2026-02-21 15:48:02 +00:00
|
|
|
self,
|
|
|
|
|
user_id: int,
|
|
|
|
|
listing_id: int,
|
|
|
|
|
listing_type: str,
|
|
|
|
|
decision: str,
|
wrongmove: add "seen" soft-hide decision with price-aware resurfacing
Opening a listing's detail sheet for >3s now passively marks it `seen`
and snapshots its current `total_price`. Seen listings are hidden from
the main list by default but automatically resurface when the price
changes (any direction). Distinct from `disliked` — explicit
like/dislike always overrides the passive seen state.
New "Hidden (N)" toggle on the FilterBar appears whenever at least one
listing is currently being hidden by the seen filter. Toggling it
reveals those rows in-place (without unmarking them) so the user can
review or explicitly clear via the existing Like/Dislike/Clear flow.
## Backend
- Alembic f7a8b9c0d1e2: `ALTER TABLE listingdecision ADD COLUMN
price_at_decision FLOAT NULL`.
- `models/decision.py`: ListingDecision gains nullable
`price_at_decision: float | None`.
- `services/decision_service.py`: adds `seen` to VALID_DECISIONS;
set_decision accepts an optional `price_at_decision`; it's only
forwarded to the repo for decision='seen' (other types null-out the
column to keep semantics clean).
- `repositories/decision_repository.py`: upsert_decision now carries
price_at_decision through the MySQL + SQLite upsert paths.
- `api/decision_routes.py`: SetDecisionRequest + DecisionResponse
expose the new field.
## Frontend
- `types/index.ts`: DecisionType = 'liked' | 'disliked' | 'seen';
ListingDecision gains `price_at_decision?: number | null`.
- `services/decisionService.ts`: setDecision sends the price only for
decision='seen' (and only when it's a finite number).
- `hooks/useDecisions.ts`: rewritten to store `Map<key, DecisionEntry>`
(decision + price snapshot). New `markSeen(id, price, type)` short-
circuits on existing liked/disliked. New `getDecisionEntry`,
`seenCount`.
- `App.tsx`: 3s `setTimeout` dwell timer fires markSeen when the
detail sheet stays open. Filter logic in `processedListingData`
hides `seen` rows whose `total_price === price_at_decision`, with
`showHidden` bypass. Computes `hiddenCount` to drive the toggle.
- `components/FilterBar.tsx`: new conditional "Hidden (N)" / "Showing
hidden (N)" toggle button (Eye / EyeOff lucide icons), surfaces only
when hiddenCount > 0.
## Tests
- pytest: 2 new (test_set_seen_carries_price, test_liked_drops_price_
even_if_supplied) + 1 updated to assert the new 5-arg repo
signature. 24 passed.
- vitest: 6 new for useDecisions (markSeen liked/disliked skip, price
snapshot, re-mark, null price, seenCount) + 5 new for decisionService
payload shape. 221 total passed, tsc clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 11:07:44 +00:00
|
|
|
price_at_decision: float | None = None,
|
2026-02-21 13:52:20 +00:00
|
|
|
) -> ListingDecision:
|
2026-02-21 15:48:02 +00:00
|
|
|
"""Create or update a decision. Uses dialect-specific upsert."""
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
t0 = time.monotonic()
|
2026-02-21 13:52:20 +00:00
|
|
|
with Session(self.engine) as session:
|
2026-02-21 15:48:02 +00:00
|
|
|
now = datetime.utcnow()
|
|
|
|
|
values = {
|
|
|
|
|
"user_id": user_id,
|
|
|
|
|
"listing_id": listing_id,
|
|
|
|
|
"listing_type": listing_type,
|
|
|
|
|
"decision": decision,
|
wrongmove: add "seen" soft-hide decision with price-aware resurfacing
Opening a listing's detail sheet for >3s now passively marks it `seen`
and snapshots its current `total_price`. Seen listings are hidden from
the main list by default but automatically resurface when the price
changes (any direction). Distinct from `disliked` — explicit
like/dislike always overrides the passive seen state.
New "Hidden (N)" toggle on the FilterBar appears whenever at least one
listing is currently being hidden by the seen filter. Toggling it
reveals those rows in-place (without unmarking them) so the user can
review or explicitly clear via the existing Like/Dislike/Clear flow.
## Backend
- Alembic f7a8b9c0d1e2: `ALTER TABLE listingdecision ADD COLUMN
price_at_decision FLOAT NULL`.
- `models/decision.py`: ListingDecision gains nullable
`price_at_decision: float | None`.
- `services/decision_service.py`: adds `seen` to VALID_DECISIONS;
set_decision accepts an optional `price_at_decision`; it's only
forwarded to the repo for decision='seen' (other types null-out the
column to keep semantics clean).
- `repositories/decision_repository.py`: upsert_decision now carries
price_at_decision through the MySQL + SQLite upsert paths.
- `api/decision_routes.py`: SetDecisionRequest + DecisionResponse
expose the new field.
## Frontend
- `types/index.ts`: DecisionType = 'liked' | 'disliked' | 'seen';
ListingDecision gains `price_at_decision?: number | null`.
- `services/decisionService.ts`: setDecision sends the price only for
decision='seen' (and only when it's a finite number).
- `hooks/useDecisions.ts`: rewritten to store `Map<key, DecisionEntry>`
(decision + price snapshot). New `markSeen(id, price, type)` short-
circuits on existing liked/disliked. New `getDecisionEntry`,
`seenCount`.
- `App.tsx`: 3s `setTimeout` dwell timer fires markSeen when the
detail sheet stays open. Filter logic in `processedListingData`
hides `seen` rows whose `total_price === price_at_decision`, with
`showHidden` bypass. Computes `hiddenCount` to drive the toggle.
- `components/FilterBar.tsx`: new conditional "Hidden (N)" / "Showing
hidden (N)" toggle button (Eye / EyeOff lucide icons), surfaces only
when hiddenCount > 0.
## Tests
- pytest: 2 new (test_set_seen_carries_price, test_liked_drops_price_
even_if_supplied) + 1 updated to assert the new 5-arg repo
signature. 24 passed.
- vitest: 6 new for useDecisions (markSeen liked/disliked skip, price
snapshot, re-mark, null price, seenCount) + 5 new for decisionService
payload shape. 221 total passed, tsc clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 11:07:44 +00:00
|
|
|
"price_at_decision": price_at_decision,
|
2026-02-21 15:48:02 +00:00
|
|
|
"created_at": now,
|
|
|
|
|
"updated_at": now,
|
|
|
|
|
}
|
|
|
|
|
dialect = self.engine.dialect.name
|
|
|
|
|
if dialect == "mysql":
|
|
|
|
|
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
|
|
|
|
stmt = mysql_insert(ListingDecision).values(**values)
|
|
|
|
|
stmt = stmt.on_duplicate_key_update(
|
|
|
|
|
decision=stmt.inserted.decision,
|
wrongmove: add "seen" soft-hide decision with price-aware resurfacing
Opening a listing's detail sheet for >3s now passively marks it `seen`
and snapshots its current `total_price`. Seen listings are hidden from
the main list by default but automatically resurface when the price
changes (any direction). Distinct from `disliked` — explicit
like/dislike always overrides the passive seen state.
New "Hidden (N)" toggle on the FilterBar appears whenever at least one
listing is currently being hidden by the seen filter. Toggling it
reveals those rows in-place (without unmarking them) so the user can
review or explicitly clear via the existing Like/Dislike/Clear flow.
## Backend
- Alembic f7a8b9c0d1e2: `ALTER TABLE listingdecision ADD COLUMN
price_at_decision FLOAT NULL`.
- `models/decision.py`: ListingDecision gains nullable
`price_at_decision: float | None`.
- `services/decision_service.py`: adds `seen` to VALID_DECISIONS;
set_decision accepts an optional `price_at_decision`; it's only
forwarded to the repo for decision='seen' (other types null-out the
column to keep semantics clean).
- `repositories/decision_repository.py`: upsert_decision now carries
price_at_decision through the MySQL + SQLite upsert paths.
- `api/decision_routes.py`: SetDecisionRequest + DecisionResponse
expose the new field.
## Frontend
- `types/index.ts`: DecisionType = 'liked' | 'disliked' | 'seen';
ListingDecision gains `price_at_decision?: number | null`.
- `services/decisionService.ts`: setDecision sends the price only for
decision='seen' (and only when it's a finite number).
- `hooks/useDecisions.ts`: rewritten to store `Map<key, DecisionEntry>`
(decision + price snapshot). New `markSeen(id, price, type)` short-
circuits on existing liked/disliked. New `getDecisionEntry`,
`seenCount`.
- `App.tsx`: 3s `setTimeout` dwell timer fires markSeen when the
detail sheet stays open. Filter logic in `processedListingData`
hides `seen` rows whose `total_price === price_at_decision`, with
`showHidden` bypass. Computes `hiddenCount` to drive the toggle.
- `components/FilterBar.tsx`: new conditional "Hidden (N)" / "Showing
hidden (N)" toggle button (Eye / EyeOff lucide icons), surfaces only
when hiddenCount > 0.
## Tests
- pytest: 2 new (test_set_seen_carries_price, test_liked_drops_price_
even_if_supplied) + 1 updated to assert the new 5-arg repo
signature. 24 passed.
- vitest: 6 new for useDecisions (markSeen liked/disliked skip, price
snapshot, re-mark, null price, seenCount) + 5 new for decisionService
payload shape. 221 total passed, tsc clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 11:07:44 +00:00
|
|
|
price_at_decision=stmt.inserted.price_at_decision,
|
2026-02-21 15:48:02 +00:00
|
|
|
updated_at=stmt.inserted.updated_at,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
|
|
|
|
stmt = sqlite_insert(ListingDecision).values(**values)
|
|
|
|
|
stmt = stmt.on_conflict_do_update(
|
|
|
|
|
index_elements=["user_id", "listing_id", "listing_type"],
|
|
|
|
|
set_={
|
|
|
|
|
"decision": stmt.excluded.decision,
|
wrongmove: add "seen" soft-hide decision with price-aware resurfacing
Opening a listing's detail sheet for >3s now passively marks it `seen`
and snapshots its current `total_price`. Seen listings are hidden from
the main list by default but automatically resurface when the price
changes (any direction). Distinct from `disliked` — explicit
like/dislike always overrides the passive seen state.
New "Hidden (N)" toggle on the FilterBar appears whenever at least one
listing is currently being hidden by the seen filter. Toggling it
reveals those rows in-place (without unmarking them) so the user can
review or explicitly clear via the existing Like/Dislike/Clear flow.
## Backend
- Alembic f7a8b9c0d1e2: `ALTER TABLE listingdecision ADD COLUMN
price_at_decision FLOAT NULL`.
- `models/decision.py`: ListingDecision gains nullable
`price_at_decision: float | None`.
- `services/decision_service.py`: adds `seen` to VALID_DECISIONS;
set_decision accepts an optional `price_at_decision`; it's only
forwarded to the repo for decision='seen' (other types null-out the
column to keep semantics clean).
- `repositories/decision_repository.py`: upsert_decision now carries
price_at_decision through the MySQL + SQLite upsert paths.
- `api/decision_routes.py`: SetDecisionRequest + DecisionResponse
expose the new field.
## Frontend
- `types/index.ts`: DecisionType = 'liked' | 'disliked' | 'seen';
ListingDecision gains `price_at_decision?: number | null`.
- `services/decisionService.ts`: setDecision sends the price only for
decision='seen' (and only when it's a finite number).
- `hooks/useDecisions.ts`: rewritten to store `Map<key, DecisionEntry>`
(decision + price snapshot). New `markSeen(id, price, type)` short-
circuits on existing liked/disliked. New `getDecisionEntry`,
`seenCount`.
- `App.tsx`: 3s `setTimeout` dwell timer fires markSeen when the
detail sheet stays open. Filter logic in `processedListingData`
hides `seen` rows whose `total_price === price_at_decision`, with
`showHidden` bypass. Computes `hiddenCount` to drive the toggle.
- `components/FilterBar.tsx`: new conditional "Hidden (N)" / "Showing
hidden (N)" toggle button (Eye / EyeOff lucide icons), surfaces only
when hiddenCount > 0.
## Tests
- pytest: 2 new (test_set_seen_carries_price, test_liked_drops_price_
even_if_supplied) + 1 updated to assert the new 5-arg repo
signature. 24 passed.
- vitest: 6 new for useDecisions (markSeen liked/disliked skip, price
snapshot, re-mark, null price, seenCount) + 5 new for decisionService
payload shape. 221 total passed, tsc clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 11:07:44 +00:00
|
|
|
"price_at_decision": stmt.excluded.price_at_decision,
|
2026-02-21 15:48:02 +00:00
|
|
|
"updated_at": stmt.excluded.updated_at,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
session.execute(stmt)
|
2026-02-21 13:52:20 +00:00
|
|
|
session.commit()
|
2026-02-21 15:48:02 +00:00
|
|
|
# Fetch the result
|
|
|
|
|
result = session.exec(
|
|
|
|
|
select(ListingDecision).where(
|
|
|
|
|
ListingDecision.user_id == user_id,
|
|
|
|
|
ListingDecision.listing_id == listing_id,
|
|
|
|
|
ListingDecision.listing_type == listing_type,
|
|
|
|
|
)
|
|
|
|
|
).first()
|
|
|
|
|
assert result is not None
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
record_db_query("upsert_decision", "decision", time.monotonic() - t0)
|
|
|
|
|
return result
|
2026-02-21 13:52:20 +00:00
|
|
|
|
|
|
|
|
def get_decisions_for_user(self, user_id: int) -> list[ListingDecision]:
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
t0 = time.monotonic()
|
2026-02-21 13:52:20 +00:00
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
statement = select(ListingDecision).where(
|
|
|
|
|
ListingDecision.user_id == user_id
|
|
|
|
|
)
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
results = list(session.exec(statement).all())
|
|
|
|
|
record_db_query("get_decisions_for_user", "decision", time.monotonic() - t0, len(results))
|
|
|
|
|
return results
|
2026-02-21 13:52:20 +00:00
|
|
|
|
|
|
|
|
def delete_decision(
|
2026-02-21 15:48:02 +00:00
|
|
|
self,
|
|
|
|
|
user_id: int,
|
|
|
|
|
listing_id: int,
|
|
|
|
|
listing_type: str,
|
2026-02-21 13:52:20 +00:00
|
|
|
) -> bool:
|
|
|
|
|
with Session(self.engine) as session:
|
2026-02-21 15:48:02 +00:00
|
|
|
result = session.exec(
|
|
|
|
|
select(ListingDecision).where(
|
|
|
|
|
ListingDecision.user_id == user_id,
|
|
|
|
|
ListingDecision.listing_id == listing_id,
|
|
|
|
|
ListingDecision.listing_type == listing_type,
|
|
|
|
|
)
|
|
|
|
|
).first()
|
|
|
|
|
if result is None:
|
2026-02-21 13:52:20 +00:00
|
|
|
return False
|
2026-02-21 15:48:02 +00:00
|
|
|
session.delete(result)
|
2026-02-21 13:52:20 +00:00
|
|
|
session.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def get_disliked_listing_ids(
|
2026-02-21 15:48:02 +00:00
|
|
|
self,
|
|
|
|
|
user_id: int,
|
|
|
|
|
listing_type: str,
|
2026-02-21 13:52:20 +00:00
|
|
|
) -> set[int]:
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
t0 = time.monotonic()
|
2026-02-21 13:52:20 +00:00
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
statement = select(ListingDecision.listing_id).where(
|
|
|
|
|
ListingDecision.user_id == user_id,
|
|
|
|
|
ListingDecision.listing_type == listing_type,
|
|
|
|
|
ListingDecision.decision == "disliked",
|
|
|
|
|
)
|
Add navigation & usage metrics for end-user experience visibility
Instrument DB query timing (11 operations across 3 repositories),
streaming lifecycle (TTFB, duration, feature count), cache operation
latency, listing detail step breakdown, and frontend page load /
time-to-first-listing / stream download / detail load metrics.
Adds 16 new OTel instruments, extends the perf ingestion endpoint
with 4 new frontend metrics, and adds ~20 Grafana dashboard panels
across 4 new rows (DB Query Performance, Streaming Performance,
Listing Detail Breakdown, Cache Performance, Frontend Navigation).
2026-02-23 20:28:42 +00:00
|
|
|
ids = {row for row in session.exec(statement).all()}
|
|
|
|
|
record_db_query("get_disliked_listing_ids", "decision", time.monotonic() - t0, len(ids))
|
|
|
|
|
return ids
|
2026-02-21 15:48:02 +00:00
|
|
|
|
|
|
|
|
def get_liked_listing_ids(
|
|
|
|
|
self,
|
|
|
|
|
user_id: int,
|
|
|
|
|
listing_type: str,
|
|
|
|
|
) -> set[int]:
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
statement = select(ListingDecision.listing_id).where(
|
|
|
|
|
ListingDecision.user_id == user_id,
|
|
|
|
|
ListingDecision.listing_type == listing_type,
|
|
|
|
|
ListingDecision.decision == "liked",
|
|
|
|
|
)
|
|
|
|
|
return {row for row in session.exec(statement).all()}
|