Refactor GetAnnunciParsed and ParseAnnunci to include forceImages parameter for improved image processing control

This commit is contained in:
Marco Pedone 2025-10-29 12:27:52 +01:00
parent fddf212c6d
commit 527a7d7f57
3 changed files with 25 additions and 34 deletions

View file

@ -90,15 +90,15 @@ func (m *MiogestHandler) GenerateCategorie() {
}
// 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
m.AnnunciParsed = m.ParseAnnunci("", p)
m.AnnunciParsed = m.ParseAnnunci("", p, forceImages)
return m.AnnunciParsed
}
// versione per singolo annuncio
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 {
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()
if len(annunci.Annuncio) == 0 {
@ -126,16 +126,26 @@ func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToP
image_codes_to_process := []string{}
if config.Cfg.Images.Enabled {
var err error
image_codes_to_process, err = CodiciToProcessImages(&annunci)
if err != nil {
log.Fatalf("Failed to find images to update: %v", 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)
if err != nil {
log.Fatalf("Failed to find images to update: %v", err.Error())
}
}
if codFilter != "" {
// if processing single codice, ensure it's in the list
if !slices.Contains(image_codes_to_process, codFilter) {
image_codes_to_process = append(image_codes_to_process, codFilter)
}
}
err = ForceClearImages(image_codes_to_process)
if err != nil {

View file

@ -104,14 +104,19 @@ func (s *Server) SetupRoutes() *echo.Echo {
})
e.GET("/parse", func(c echo.Context) error {
start := time.Now()
var data = s.miogest.GetAnnunciParsed(nil)
var data = s.miogest.GetAnnunciParsed(nil, false)
end := time.Now()
fmt.Println("time taken:", end.Sub(start).String())
return c.JSONPretty(http.StatusOK, data, " ")
})
e.GET("/update", func(c echo.Context) error {
forceImages := false
forceImagesStr := c.QueryParam("forceimages")
if forceImagesStr == "true" {
forceImages = true
}
imgPool := []typesdefs.ImagesToProcess{}
var data = s.miogest.GetAnnunciParsed(&imgPool)
var data = s.miogest.GetAnnunciParsed(&imgPool, forceImages)
imgRefs, err := ProcessImagePool(&imgPool)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())

View file

@ -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;