fix(workspace): reconcile listed repos with the configured (postgres) DB - #1853
fix(workspace): reconcile listed repos with the configured (postgres) DB#1853sloemo01 wants to merge 2 commits into
Conversation
|
📋 At a glance Files & modules (2)
✅ Health gate: passed 📌 Before you merge
🔎 More signals (2)🗺️ Change map flowchart LR
subgraph PR ["Changed in this PR (2 with dependents)"]
f_packages_server_src_repowise_server_routers_workspace_py[".../routers/workspace.py 🔥"]:::changed
f_tests_unit_server_test_workspace_router_py[".../server/test_workspace_router.py"]:::changed
end
f_packages_cli_src_repowise_cli_commands_workspace_cmd_py[".../commands/workspace_cmd.py"]
f_packages_server_src_repowise_server_routers_workspace_py --> f_packages_cli_src_repowise_cli_commands_workspace_cmd_py
f_packages_cli_src_repowise_cli_helpers_py[".../cli/helpers.py"]
f_packages_server_src_repowise_server_routers_workspace_py --> f_packages_cli_src_repowise_cli_helpers_py
f_packages_core_src_repowise_core_workspace_config_py[".../workspace/config.py"]
f_packages_server_src_repowise_server_routers_workspace_py --> f_packages_core_src_repowise_core_workspace_config_py
f_packages_core_src_repowise_core_workspace_contracts_py[".../workspace/contracts.py"]
f_packages_server_src_repowise_server_routers_workspace_py --> f_packages_core_src_repowise_core_workspace_contracts_py
f_packages_server_src_repowise_server_schemas_workspace_py[".../schemas/workspace.py"]
f_tests_unit_server_test_workspace_router_py --> f_packages_server_src_repowise_server_schemas_workspace_py
more(["+3 more dependents"])
PR --> more
t_tests_unit_server_test_workspace_sidebar_py(["✅ .../server/test_workspace_sidebar.py"]):::guard
t_tests_unit_server_test_workspace_sidebar_py -.-> f_packages_server_src_repowise_server_routers_workspace_py
classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Solid arrows: code that imports the changed files (8 direct dependents, from the last indexed snapshot). Dashed: history/tests. 🔥 Hotspots touched (2)
👀 Suggested reviewers @RaghavChamadiya 📊 See the full report for this PR |
|
@sloemo01 Just a couple of small observations that might be helpful before maintainers review:
I may be wrong but you can verify this once ! |
…gres) DB on sync sync_workspace gated first-time indexing on whether a local .repoweise/wiki.db file exists. Under PostgreSQL repos are indexed into the shared DB with no per-repo wiki.db, so every sync wrongly re-indexed them. Check the configured session factory for an existing Repository row instead of the file presence (issue repowise-dev#1034).
|
Thanks for the detailed review, @akshatmalik-bruh — both points are good. On the POST /api/workspace/sync one: you were right, it was a real bug. It gated first-time indexing on On the session-architecture consolidation point: agreed it would be cleaner and prevent drift between the sqlite3 and Postgres helpers. That is a larger refactor than this PR should carry, so I have left it out of scope here — but it is worth doing as its own change. Happy to take it on as a follow-up if you want it. |
|
@RaghavChamadiya take a look at this once ! |
Ayush7614
left a comment
There was a problem hiding this comment.
Verified: pytest tests/unit/server/test_workspace_router.py -q 45/45 passed including new test_configured_db_repo_reported_as_indexed (Postgres fallback without local wiki.db). Fixes #1034 — _query_repo_stats and _query_top_language now prefer repo-local SQLite then fall back to session_factory keyed by local_path, and sync_workspace checks the DB row before re-indexing (addressing @akshatmalik-bruh's point).\n\nThank you @akshatmalik-bruh for the thorough review — both observations were spot-on (session-factory consolidation vs dual path, and the POST /api/workspace/sync db_path.exists bug). @sloemo01 addressed the second point with a fix that keeps 45/45 green while leaving the larger consolidation as a clean follow-up as you both agreed. Great collaboration.\n\nLGTM — approved.
Summary
Fixes #1034.
When the server is configured with a PostgreSQL database (
REPOWISE_DB_URL/REPOWISE_DATABASE_URL),GET /api/workspaceandGET /api/workspace/graphlisted repos by walking the root directory and reading a repo-local
.repowise/wiki.dbSQLite file. Repos indexed into the configured (postgres)DB keyed by
local_pathhave no localwiki.db, so they were reported asneeds_index/missing_dirwith zero stats — even though they were alreadyindexed.
Change
_query_repo_statsand_query_top_languageinpackages/server/src/repowise/server/routers/workspace.pynow:wiki.dbwhen present (unchanged behaviour),(
app.state.session_factory) keyed by the repo's absolutelocal_path,aggregating the same tables (
repositories,graph_nodes,wiki_pages,git_metadata,health_file_metrics) the SQLite path reads.The helpers became
async; both callers (/api/workspace,/api/workspace/graph)were updated to
awaitthem and pass the session factory.Tests
test_configured_db_repo_reported_as_indexedcovering a repo indexedin the configured DB (no local
wiki.db) being reported asindexedwithits
repo_id.TestQueryRepoStatsunit tests for the now-asynchelpers.