Refactor GetAnnunciParsed and ParseAnnunci to include forceImages parameter for improved image processing control
This commit is contained in:
parent
fddf212c6d
commit
527a7d7f57
3 changed files with 25 additions and 34 deletions
|
|
@ -90,15 +90,15 @@ func (m *MiogestHandler) GenerateCategorie() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ANNUNCI PARSED
|
// ANNUNCI PARSED
|
||||||
func (m *MiogestHandler) GetAnnunciParsed(p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed {
|
func (m *MiogestHandler) GetAnnunciParsed(p *[]typesdefs.ImagesToProcess, forceImages bool) typesdefs.AnnunciParsed {
|
||||||
// salvo il parsing nello struct nel caso voglio implementare un caching e non fare il parsing ad ogni chiamata
|
// salvo il parsing nello struct nel caso voglio implementare un caching e non fare il parsing ad ogni chiamata
|
||||||
m.AnnunciParsed = m.ParseAnnunci("", p)
|
m.AnnunciParsed = m.ParseAnnunci("", p, forceImages)
|
||||||
return m.AnnunciParsed
|
return m.AnnunciParsed
|
||||||
}
|
}
|
||||||
|
|
||||||
// versione per singolo annuncio
|
// versione per singolo annuncio
|
||||||
func (m *MiogestHandler) GetAnnuncioParsed(codFilter string, p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed {
|
func (m *MiogestHandler) GetAnnuncioParsed(codFilter string, p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed {
|
||||||
data := m.ParseAnnunci(codFilter, p)
|
data := m.ParseAnnunci(codFilter, p, false)
|
||||||
if len(data.Annuncio) == 0 {
|
if len(data.Annuncio) == 0 {
|
||||||
return typesdefs.AnnunciParsed{}
|
return typesdefs.AnnunciParsed{}
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ func (m *MiogestHandler) GetAnnuncioParsed(codFilter string, p *[]typesdefs.Imag
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed {
|
func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToProcess, forceImages bool) typesdefs.AnnunciParsed {
|
||||||
annunci := m.GetAnnunci()
|
annunci := m.GetAnnunci()
|
||||||
|
|
||||||
if len(annunci.Annuncio) == 0 {
|
if len(annunci.Annuncio) == 0 {
|
||||||
|
|
@ -126,16 +126,26 @@ func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToP
|
||||||
image_codes_to_process := []string{}
|
image_codes_to_process := []string{}
|
||||||
if config.Cfg.Images.Enabled {
|
if config.Cfg.Images.Enabled {
|
||||||
var err error
|
var err error
|
||||||
|
if forceImages {
|
||||||
|
// process all images
|
||||||
|
image_codes_to_process = make([]string, 0, len(annunci.Annuncio))
|
||||||
|
for _, annuncio := range annunci.Annuncio {
|
||||||
|
if annuncio.Codice != nil {
|
||||||
|
image_codes_to_process = append(image_codes_to_process, *annuncio.Codice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// process only new or updated images
|
||||||
image_codes_to_process, err = CodiciToProcessImages(&annunci)
|
image_codes_to_process, err = CodiciToProcessImages(&annunci)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to find images to update: %v", err.Error())
|
log.Fatalf("Failed to find images to update: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if codFilter != "" {
|
if codFilter != "" {
|
||||||
// if processing single codice, ensure it's in the list
|
// if processing single codice, ensure it's in the list
|
||||||
if !slices.Contains(image_codes_to_process, codFilter) {
|
if !slices.Contains(image_codes_to_process, codFilter) {
|
||||||
image_codes_to_process = append(image_codes_to_process, codFilter)
|
image_codes_to_process = append(image_codes_to_process, codFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
err = ForceClearImages(image_codes_to_process)
|
err = ForceClearImages(image_codes_to_process)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -104,14 +104,19 @@ func (s *Server) SetupRoutes() *echo.Echo {
|
||||||
})
|
})
|
||||||
e.GET("/parse", func(c echo.Context) error {
|
e.GET("/parse", func(c echo.Context) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
var data = s.miogest.GetAnnunciParsed(nil)
|
var data = s.miogest.GetAnnunciParsed(nil, false)
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
fmt.Println("time taken:", end.Sub(start).String())
|
fmt.Println("time taken:", end.Sub(start).String())
|
||||||
return c.JSONPretty(http.StatusOK, data, " ")
|
return c.JSONPretty(http.StatusOK, data, " ")
|
||||||
})
|
})
|
||||||
e.GET("/update", func(c echo.Context) error {
|
e.GET("/update", func(c echo.Context) error {
|
||||||
|
forceImages := false
|
||||||
|
forceImagesStr := c.QueryParam("forceimages")
|
||||||
|
if forceImagesStr == "true" {
|
||||||
|
forceImages = true
|
||||||
|
}
|
||||||
imgPool := []typesdefs.ImagesToProcess{}
|
imgPool := []typesdefs.ImagesToProcess{}
|
||||||
var data = s.miogest.GetAnnunciParsed(&imgPool)
|
var data = s.miogest.GetAnnunciParsed(&imgPool, forceImages)
|
||||||
imgRefs, err := ProcessImagePool(&imgPool)
|
imgRefs, err := ProcessImagePool(&imgPool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.String(http.StatusInternalServerError, err.Error())
|
return c.String(http.StatusInternalServerError, err.Error())
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
INSERT INTO
|
|
||||||
PUBLIC.USERS (
|
|
||||||
username,
|
|
||||||
email,
|
|
||||||
"isAdmin",
|
|
||||||
PASSWORD,
|
|
||||||
nome,
|
|
||||||
cognome,
|
|
||||||
"isVerified",
|
|
||||||
salt,
|
|
||||||
telefono
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
'Francesco Infoalloggi'::TEXT,
|
|
||||||
'commerciale@infoalloggi.it'::TEXT,
|
|
||||||
TRUE::BOOLEAN,
|
|
||||||
'changeme'::TEXT,
|
|
||||||
'Francesco'::TEXT,
|
|
||||||
'Infoalloggi'::TEXT,
|
|
||||||
TRUE::BOOLEAN,
|
|
||||||
'a'::TEXT,
|
|
||||||
'+393407246729'::TEXT
|
|
||||||
)
|
|
||||||
ON CONFLICT (email) DO NOTHING;
|
|
||||||
Loading…
Add table
Reference in a new issue