Skip to content

Refactor: remove duplicated and unused code #74

Closed

Description

@uniqueg

Why?

The code has accumulated duplication and dead code that makes changes such as #62 and #61 larger and riskier than necessary:

  • The services collection is looked up with the same three lines (current_app.config.foca.db.dbs["serviceStore"].collections["services"].client) in getServices, getServiceById, deleteService and RegisterService.__init__, and the service-info collection in the same way in RegisterServiceInfo.__init__.
  • postService and putService in cloud_registry/ga4gh/registry/server.py are almost identical.
  • getServiceTypes loads all services and deduplicates their types in Python through a set, so the order of the returned types changes between calls.
  • getServiceById deletes _id by hand instead of using a projection, unlike getServices.
  • Unused code: import string # noqa: F401 in service.py; ValidationError in exceptions.py (only mentioned in a docstring of set_service_info_from_config, which never raises it); MetaVersionConfig and custom.endpoints.services.meta_version (configured, never read); RegisterService.was_replaced (set, never read); the config-file existence check in app.py, which FOCA does anyway.
  • Module paths only work because app.py is run as a script from inside cloud_registry/: custom_config_model="service_models.custom_config.CustomConfig" in app.py, and x-openapi-router-controller: ga4gh.registry.server and x-bearerInfoFunc: app.validate_token in config.yaml. The app cannot be started as an installed package (e.g. python -m cloud_registry.app).
  • f-strings in logging calls (app.py, service.py) and Pydantic v1 .dict() in service_info.py.

How?

  1. Add one helper that returns a collection client by name and use it everywhere.
  2. Merge the shared logic of postService and putService into one function.
  3. Compute the distinct service types in MongoDB (aggregation or distinct) and return them in a stable order.
  4. Use projections instead of deleting _id.
  5. Remove the unused code listed above (including the meta_version config key, with a note in the changelog).
  6. Use fully qualified module paths (cloud_registry.service_models.custom_config.CustomConfig, cloud_registry.ga4gh.registry.server, foca.security.auth.validate_token), and start the app with python -m cloud_registry.app in the Dockerfile.
  7. Use %-style logging and model_dump().

Behavior of the API must not change; the app-level tests from #71 serve as the safety net.

Acceptance criteria

  • No duplicated collection lookups or POST/PUT logic remain.
  • GET /services/types returns the same order on repeated calls.
  • The app starts with python -m cloud_registry.app; Docker and Compose use it.
  • All tests pass unchanged (apart from tests of removed code).

Dependencies: #71; after #65. Coordinate with #66 (touches the same controllers).

Activity

  1. added
    priority: medium
    type: maintenance
    workload: hours
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: maintenanceworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions