public void getEntityWithParents(List<DBEntity> entityList, String id) { DBEntity entity = dao.getById(id); entityList.add(entity); if (entity.getParent() != null) { getEntityWithParents(entityList, entity.getId()); } }
Because I'm working from a make it work first then make it efficient perspective I realize that I'm making a lot of DB calls there. So I pop open gemini, copy/paste that algorithm and ask it "How can I replace this method with a single call to the database, in postgresql?" and it gives me
WITH RECURSIVE parent_chain AS (SELECT id, name, parent, 0 AS depth FROM table WHERE id = :id UNION ALL SELECT i.id, i.name, i.parent, pc.depth + 1 FROM fam.dx_concept i INNER JOIN parent_chain pc ON i.id = pc.parent) SELECT id, name, parent FROM parent_chain ORDER BY depth;
That might have been a day or two of research, instead it was 5 minutes to come up with a theory and an hour or so writing tests. Gemini saved the day there. But it wasn't able to determine what needed done (minimizing DB calls), only how to do it, and it wasn't able to verify correctness. That's where we'll fit in in all of this: figuring out what to do and then making sure we actually did it.