Conversation
Reviewer's GuideAdds a full unit display-name extraction and lookup pipeline (CLI, startup integration, API wiring, and frontend usage) so that DCS unit type codes can be shown with human-readable names, plus minor logging and config extensions. Sequence diagram for unit display name extraction at server startupsequenceDiagram
participant FastAPIApp as FastAPI_app
participant Lifespan as lifespan
participant Config as get_config
participant UnitNames as unit_names
participant FS as FileSystem
FastAPIApp->>Lifespan: start (lifespan hook)
Lifespan->>Lifespan: _configure_logging()
Lifespan->>Config: get_config()
Config-->>Lifespan: Config(dcs.install_path)
Lifespan->>FS: check Path(dcs.install_path).exists()
alt install_path exists
Lifespan->>UnitNames: refresh_unit_display_names(dcs_install)
UnitNames->>UnitNames: extract_all(dcs_install)
UnitNames->>FS: glob Lua files
FS-->>UnitNames: Lua file paths
loop for each Lua file
UnitNames->>UnitNames: extract_from_file(lua_file)
end
UnitNames->>UnitNames: save_unit_display_names(mappings)
UnitNames->>FS: write var/unit_display_names.json
UnitNames-->>Lifespan: count
Lifespan->>UnitNames: get_unit_display_names()
UnitNames-->>Lifespan: mapping
Lifespan->>UnitNames: get_unit_display_names.cache_clear()
else install_path configured but missing
Lifespan->>Lifespan: log warning
else install_path not configured
Lifespan->>FS: check UNIT_NAMES_PATH.exists()
alt unit names file exists
Lifespan->>UnitNames: get_unit_display_names()
UnitNames-->>Lifespan: mapping
else no file
Lifespan->>Lifespan: log info (codes will be shown as-is)
end
end
Lifespan-->>FastAPIApp: startup complete
FastAPIApp-->>Lifespan: shutdown
Lifespan-->>FastAPIApp: lifespan exit
Sequence diagram for map data request and unit display name usagesequenceDiagram
actor User as Browser_user
participant Browser as Browser_JS
participant API as FastAPI_foothold_get_map_data
participant UnitNames as unit_names
User->>Browser: Open map page
Browser->>API: GET /api/map_data
API->>API: build sitac data
API->>API: collect all_unit_types from zones
API->>UnitNames: get_unit_display_names()
UnitNames-->>API: full_mapping{type_lower:display_name}
API->>API: unit_display_names = filtered mapping
API-->>Browser: MapData(unit_display_names,…)
Browser->>Browser: unitDisplayNames = data.unit_display_names
User->>Browser: Open zone modal
Browser->>Browser: openZoneModal(zone)
Browser->>Browser: for each group.units
Browser->>Browser: lookup unitDisplayNames[unitType]
Browser->>Browser: render <span title=displayName>unitType xN</span>
User->>Browser: Hover unit type
Browser-->>User: Show human readable tooltip
Updated class diagram for unit names pipeline and configclassDiagram
class DcsConfig {
str saved_games
str~None install_path
}
class MapData {
dict~str,str~ unit_display_names
}
class UnitNamesModule {
+Path UNIT_NAMES_PATH
+dict~str,str~ extract_from_file(filepath: Path)
+dict~str,str~ extract_all(dcs_path: Path)
+void save_unit_display_names(mappings: dict~str,str~, output: Path)
+int refresh_unit_display_names(dcs_path: Path)
+dict~str,str~ get_unit_display_names()
}
class ConsoleApp {
+serve()
+extract_unit_names(dcs_path: str~None, output: Path~None)
}
class FastAPIMain {
+lifespan(application: FastAPI)
+_configure_logging()
}
class ConfigModule {
+get_config()
}
ConsoleApp ..> ConfigModule : uses get_config
ConsoleApp ..> UnitNamesModule : uses extract_all, save_unit_display_names, UNIT_NAMES_PATH
FastAPIMain ..> ConfigModule : uses get_config
FastAPIMain ..> UnitNamesModule : uses refresh_unit_display_names, get_unit_display_names, UNIT_NAMES_PATH
MapData ..> UnitNamesModule : uses get_unit_display_names
DcsConfig <.. ConfigModule : contained in Config
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/foothold_sitac/main.py" line_range="37-45" />
<code_context>
+ config = get_config()
+ dcs_install = config.dcs.install_path
+
+ if dcs_install and Path(dcs_install).exists():
+ logger.info("DCS install path configured: %s", dcs_install)
+ count = refresh_unit_display_names(Path(dcs_install))
+ if count:
+ logger.info("Refreshed %d unit display names at startup", count)
+ get_unit_display_names.cache_clear()
</code_context>
<issue_to_address>
**suggestion (performance):** Full unit-name extraction on every startup may be very slow for large DCS installs.
Calling `refresh_unit_display_names` on every startup will repeatedly scan a large portion of the DCS install tree (potentially thousands of Lua files), which can noticeably slow startup or cause timeouts in constrained environments. Consider limiting this to cases where the JSON file is missing, making it configurable, or moving the heavy extraction to an explicit CLI-only command while startup only loads the existing JSON file.
```suggestion
if dcs_install and Path(dcs_install).exists():
logger.info("DCS install path configured: %s", dcs_install)
if UNIT_NAMES_PATH.exists():
names = get_unit_display_names()
logger.info("Using existing unit display names file (%d entries)", len(names))
else:
count = refresh_unit_display_names(Path(dcs_install))
if count:
logger.info("Refreshed %d unit display names at startup", count)
get_unit_display_names.cache_clear()
else:
logger.warning("No unit mappings extracted from %s", dcs_install)
elif dcs_install:
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if dcs_install and Path(dcs_install).exists(): | ||
| logger.info("DCS install path configured: %s", dcs_install) | ||
| count = refresh_unit_display_names(Path(dcs_install)) | ||
| if count: | ||
| logger.info("Refreshed %d unit display names at startup", count) | ||
| get_unit_display_names.cache_clear() | ||
| else: | ||
| logger.warning("No unit mappings extracted from %s", dcs_install) | ||
| elif dcs_install: |
There was a problem hiding this comment.
suggestion (performance): Full unit-name extraction on every startup may be very slow for large DCS installs.
Calling refresh_unit_display_names on every startup will repeatedly scan a large portion of the DCS install tree (potentially thousands of Lua files), which can noticeably slow startup or cause timeouts in constrained environments. Consider limiting this to cases where the JSON file is missing, making it configurable, or moving the heavy extraction to an explicit CLI-only command while startup only loads the existing JSON file.
| if dcs_install and Path(dcs_install).exists(): | |
| logger.info("DCS install path configured: %s", dcs_install) | |
| count = refresh_unit_display_names(Path(dcs_install)) | |
| if count: | |
| logger.info("Refreshed %d unit display names at startup", count) | |
| get_unit_display_names.cache_clear() | |
| else: | |
| logger.warning("No unit mappings extracted from %s", dcs_install) | |
| elif dcs_install: | |
| if dcs_install and Path(dcs_install).exists(): | |
| logger.info("DCS install path configured: %s", dcs_install) | |
| if UNIT_NAMES_PATH.exists(): | |
| names = get_unit_display_names() | |
| logger.info("Using existing unit display names file (%d entries)", len(names)) | |
| else: | |
| count = refresh_unit_display_names(Path(dcs_install)) | |
| if count: | |
| logger.info("Refreshed %d unit display names at startup", count) | |
| get_unit_display_names.cache_clear() | |
| else: | |
| logger.warning("No unit mappings extracted from %s", dcs_install) | |
| elif dcs_install: |
Summary by Sourcery
Add support for extracting and serving human-readable DCS unit display names and exposing them in the map UI, with a CLI entry point and startup integration.
New Features:
Enhancements:
Documentation:
Tests: