Skip to content

Commit

Permalink
try slower implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Feb 3, 2025
1 parent fcc1b98 commit 51fe679
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def upgrade() -> None:
with open(SQL_PATH / "get_unassigned_bboxes_udf_rev2.sql") as f:
sql = f.read()
op.execute(sa.text(sql))
with open(SQL_PATH / "ALT_get_unassigned_bbox_udf.sql") as f:
sql = f.read()
op.execute(sa.text(sql))


def downgrade() -> None:
Expand Down
61 changes: 61 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,67 @@ async def get_unassigned_geoids(
return {"features": [row[0] for row in results]}


@app.get(
"/api/document/{document_id}/unassigned", response_model=UnassignedBboxGeoJSONs
)
async def get_unassigned_geoids(
document_id: str,
exclude_ids: list[str] = Query(default=[]),
session: Session = Depends(get_session),
):
print("!!!", exclude_ids)
stmt = text(
"SELECT * from find_unassigned_areas(:doc_uuid, :exclude_ids)"
).bindparams(
bindparam(key="doc_uuid", type_=UUIDType),
bindparam(key="exclude_ids", type_=ARRAY(String)),
)
results = session.execute(
stmt, {"doc_uuid": document_id, "exclude_ids": exclude_ids}
).fetchall()
return {"features": [row[0] for row in results]}


@app.get(
"/api/__unassigned/{document_id}", response_model=UnassignedBboxGeoJSONs
)

async def get_unassigned_geoids(
document_id: str,
exclude_ids: list[str] = Query(default=[]),
session: Session = Depends(get_session),
):
stmt = text(
"SELECT * from find_unassigned_areas(:doc_uuid, :exclude_ids)"
).bindparams(
bindparam(key="doc_uuid", type_=UUIDType),
bindparam(key="exclude_ids", type_=ARRAY(String)),
)
results = session.execute(
stmt, {"doc_uuid": document_id, "exclude_ids": exclude_ids}
).fetchall()
return {"features": [row[0] for row in results]}

@app.get(
"/api/__unassigned_slow/{document_id}", response_model=UnassignedBboxGeoJSONs
)

async def get_unassigned_geoids(
document_id: str,
session: Session = Depends(get_session),
):
stmt = text(
"SELECT * from get_unassigned_bboxes_slow(:doc_uuid)"
).bindparams(
bindparam(key="doc_uuid", type_=UUIDType),
bindparam(key="exclude_ids", type_=ARRAY(String)),
)
results = session.execute(
stmt, {"doc_uuid": document_id}
).fetchall()
return {"features": [row[0] for row in results]}


@app.get("/api/document/{document_id}/evaluation/{summary_stat}")
async def get_summary_stat(
document_id: str, summary_stat: str, session: Session = Depends(get_session)
Expand Down
8 changes: 4 additions & 4 deletions backend/app/sql/ALT_get_unassigned_bbox_udf.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DROP FUNCTION IF EXISTS get_unassigned_bboxes(doc_uuid uuid, exclude_ids VARCHAR[]);
CREATE OR REPLACE FUNCTION get_unassigned_bboxes(doc_uuid uuid, exclude_ids VARCHAR[])
DROP FUNCTION IF EXISTS get_unassigned_bboxes_slow(doc_uuid uuid);
CREATE OR REPLACE FUNCTION get_unassigned_bboxes_slow(doc_uuid uuid)
RETURNS TABLE (bbox json) AS $$
DECLARE
gerrydb_table text;
Expand Down Expand Up @@ -51,7 +51,7 @@ BEGIN
%s
WHERE doc.zone IS NULL
-- Exclude broken parents
AND doc.geo_id NOT IN (
AND ids.geo_id NOT IN (
SELECT DISTINCT edges.parent_path
FROM public."parentchildedges_%s" edges
INNER JOIN ids
Expand All @@ -69,6 +69,6 @@ BEGIN
ELSE ''
END,
dm_uuid
) USING doc_uuid, exclude_ids;
) USING doc_uuid;
END;
$$ LANGUAGE plpgsql;

0 comments on commit 51fe679

Please sign in to comment.