diff --git a/app/helpers/db/searchRequestMatch.js b/app/helpers/db/searchRequestMatch.js index 6dfa986..794711b 100644 --- a/app/helpers/db/searchRequestMatch.js +++ b/app/helpers/db/searchRequestMatch.js @@ -1,5 +1,7 @@ "use strict"; const db = require("../../models/index"); +const sequelize = require("sequelize"); +const Op = sequelize.Op; const { CHECK_UP_DAYS } = require("../../config/appConfig"); const findRealEstatesForSearchRequest = async searchRequestId => { @@ -53,11 +55,18 @@ const findAllRequestsForCheckUp = async () => { } }; - const excludedRequests = await db.SearchRequestMatch.findAll({ + const excludedMatches = await db.SearchRequestMatch.findAll({ attributes: ["searchRequestId"], - where: dateQuery + where: dateQuery, + order: [["searchRequestId", "ASC"]] }); + const excludedRequestsAll = excludedMatches.map(match => { + return match.dataValues.searchRequestId; + }); + //Removing duplicate search request id-s for optimization + const excludedRequests = [...new Set(excludedRequestsAll)]; + const query = { subscribed: true, id: { diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index ee30ee6..4bd2c59 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -136,9 +136,6 @@ const generateCheckUpEmail = searchRequest => { ? `
Kvadratura okućnice: Od ${gardenSizeMin} do ${gardenSizeMax} m2
` : ``; - const allRealEstatesLink = `${APP_URL}/nekretnine/${id}`; - const moreRealEstates = `
Kompletan spisak do sada pronađenih nekretnina možete pogledati na listi nekretnina
`; - const emailFooter = generateEmailFooter(id); return `

Zdravo

@@ -153,8 +150,6 @@ const generateCheckUpEmail = searchRequest => {
Cijena: ${priceMin} do ${priceMax} KM

- ${moreRealEstates} -
${emailFooter}`; }; diff --git a/index.js b/index.js index abcd14b..0669e7b 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,7 @@ const forceSSL = require("./app/helpers/forceSSL"); const { APP_PORT, CRAWLER_INTERVAL, - STOP_CRAWLER, - CHECK_UP_DAYS + STOP_CRAWLER } = require("./app/config/appConfig"); const routes = require("./app/routes"); const { crawlAll } = require("./app/crawler/crawl"); @@ -50,4 +49,4 @@ const crawl = () => { setInterval(crawl, CRAWLER_INTERVAL * 1000); -setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000); +setInterval(checkUpNotify, 1000 * 60 * 60 * 24);