Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joellensilva
Copy link
Collaborator

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 {
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

@danielfireman danielfireman left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants