-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retornando a data da última coleta #115
base: master
Are you sure you want to change the base?
Conversation
joellensilva
commented
Jun 14, 2023
- Requisito para a issue Colocar mais informações sobre o órgão site#392
if err := p.db.Model(&dto.AgencyDTO{}).Where("id = ?", aid).First(&dtoOrgao).Error; err != nil { | ||
m := p.db.Model(&dto.AgencyDTO{}).Select("orgaos.*, max(coletas.timestamp) as ultima_coleta") | ||
m = m.Joins("INNER JOIN coletas ON atual = true AND coletas.id_orgao = orgaos.id AND orgaos.id = ?", aid) | ||
if err := m.Group("orgaos.id").First(&dtoOrgao).Error; err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisamos mesmo desse agrupamento?
@@ -222,7 +222,9 @@ func (p *PostgresDB) GetAgenciesByUF(uf string) ([]models.Agency, error) { | |||
func (p *PostgresDB) GetAgency(aid string) (*models.Agency, error) { | |||
var dtoOrgao dto.AgencyDTO | |||
aid = strings.ToLower(aid) | |||
if err := p.db.Model(&dto.AgencyDTO{}).Where("id = ?", aid).First(&dtoOrgao).Error; err != nil { | |||
m := p.db.Model(&dto.AgencyDTO{}).Select("orgaos.*, max(coletas.timestamp) as ultima_coleta") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisamos mesmo desse orgaos.*
?
@@ -222,7 +222,9 @@ func (p *PostgresDB) GetAgenciesByUF(uf string) ([]models.Agency, error) { | |||
func (p *PostgresDB) GetAgency(aid string) (*models.Agency, error) { | |||
var dtoOrgao dto.AgencyDTO | |||
aid = strings.ToLower(aid) | |||
if err := p.db.Model(&dto.AgencyDTO{}).Where("id = ?", aid).First(&dtoOrgao).Error; err != nil { | |||
m := p.db.Model(&dto.AgencyDTO{}).Select("orgaos.*, max(coletas.timestamp) as ultima_coleta") | |||
m = m.Joins("INNER JOIN coletas ON atual = true AND coletas.id_orgao = orgaos.id AND orgaos.id = ?", aid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não seria melhor colocar o actual = true o orgaos.id == aid para uma cláusula where? Penso que isso vai diminuir o impacto negativo do join.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E outra coisa, cadê os testes?