meirim-org / meirim

Meirim is an open-source smart city application that facilitates transparency in urban planning.
MIT License
56 stars 24 forks source link

Scrap statuses only once a fortnight #728

Closed GalGend closed 1 year ago

GalGend commented 1 year ago

Currently, we have a status fetched that runs on all plans, regardless on the last time they were scrapped. Yet, as we don't want to exaust our servers for no reason, we want to run status fetcher only once in 14 days.

The implementation should be to fetch a plan to scrap when the last scrapping date is older than X (14) days ago.

I started to implement it but it had bugs to I detached it. It's currently commented out in the code (search for this snippet)

const fetchPlanStatus = () => {
    var mavatStatus = null;
    const planStatusLimit = Config.get('planStatusChange.limit');
    Log.info('plan limit:', planStatusLimit);
    // const lastVisitedDifference = 14; //days, may take from config
    // const timeDifference = moment.duration(lastVisitedDifference, 'd');
    // const date = moment().subtract(timeDifference);
    // const dateString = moment(date).format('YYYY-MM-DD h:mm');
    return Plan.query(qb => {
        // TODO: add outer join for not approved plans
        qb.where('status', '!=', meirimStatuses.APPROVED )
            .whereRaw('MP_ID NOT LIKE \'NOT_FOUND\'')
            // .whereRaw(`last_visited_status < '${dateString}' OR last_visited_status IS NULL`)
            .orderBy('last_visited_status','asc');
        qb.limit(planStatusLimit);
yaelal commented 1 year ago

pr https://github.com/meirim-org/meirim/pull/729

yaelal commented 1 year ago

done