Skip to content

optimize pget_db_query by allowing field filter #5372

Closed
GSA/datagov-harvester
#958

Description

@rshewitt

User Story

In order to reduce data requested from the h20 db, datagov wants to update the pget_db_query db interface function to support specific fields

Acceptance Criteria

[ACs should be clearly demoable/verifiable whenever possible. Try specifying them using BDD.]

  • GIVEN the pget_db_query function
    WHEN a list of field strings is used as input
    THEN only those fields from the model will be returned in the output

Background

  • working on #5358 I discovered that pget_db_query returns all model fields which we don't need when we're clearing out records (we only need record identifiers and the harvest source)

Security Considerations (required)

[Any security concerns that might be implicated in the change. "None" is OK, just be explicit here!]

Sketch

  • i got ahead and made this solution for #5358 but it isn't needed. here's how i did it...
def get_model_fields_by_filter(self, model, fields_filter=None):
        """
        return all Columns from the model or just those in fields_filter
        """
        if fields_filter is None:
            field_names = [field.name for field in model.__table__.columns]
        else:
            field_names = [
                field.name
                for field in model.__table__.columns
                if field.name in fields_filter
            ]

        return [getattr(model, field) for field in field_names]

#... 

def pget_db_query(self, model=None, facets="", order_by="asc", **kwargs):
       #... 
        model_data = self.get_model_fields_by_filter(
            model_name, kwargs.get("fields_filter")
        )

        return (
            self.db.query(model_name)
            .options(load_only(*model_data))
            .filter(text(facet_string))
            .order_by(order_by_val)
        )

[Notes or a checklist reflecting our understanding of the selected approach]

Activity

  1. moved this to 📥 Queue in data.gov team boardon Aug 7, 2025
  2. moved this from 📥 Queue to New 📤 Queue in data.gov team boardon Sep 16, 2025
  3. moved this from New 📤 Queue to 📥 Queue in data.gov team boardon Sep 16, 2025
  4. moved this from 📥 Queue to No status in data.gov team boardon Feb 25, 2026
  5. moved this from 📥 Queue to Next Up in data.gov team boardon Apr 23, 2026
  6. moved this from Next Up to 📥 Queue in data.gov team boardon Apr 23, 2026
  7. moved this from 📥 Queue to No status in data.gov team boardon Apr 23, 2026
  8. 2 remaining items

  9. moved this from O&M Backlog to 📥 Queue in data.gov team boardon Jun 24, 2026
  10. moved this from 📥 Queue (up next) to 📟 Sprint Backlog (Top Priority) in data.gov team boardon Sep 8, 2026
  11. self-assigned this
    on Sep 22, 2026
  12. moved this from 📟 Sprint Backlog (Top Priority) to 🏗 In Progress in data.gov team boardon Sep 22, 2026
  13. moved this from 🏗 In Progress to 👀 Needs Review in data.gov team boardon Sep 22, 2026
  14. moved this from 👀 Needs Review to ✔ Done in data.gov team boardon Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Harvest-DBPostgres and related DB tickets

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions