From c16ed2705451d79094931476e16313dcdd79c105 Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Tue, 14 Nov 2017 10:58:44 -0200
Subject: [PATCH] [ci skip] Fix cache loop in infrastrucutre

cache
ehcac
cache
ehcac
---
 src/libs/routes/infrastructure.js | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/libs/routes/infrastructure.js b/src/libs/routes/infrastructure.js
index 73b00848..ab9331cb 100644
--- a/src/libs/routes/infrastructure.js
+++ b/src/libs/routes/infrastructure.js
@@ -24,24 +24,20 @@ const cache = require('apicache').options({ debug: config.debug, statusCodes: {i
 
 let rqf = new ReqQueryFields();
 
-infrastructureApp.use(cache('15 day'));
-
 infrastructureApp.get('/year_range', cache('15 day'), (req, res, next) => {
     req.sql.from('escola')
     .field('MIN(escola.ano_censo)', 'start_year')
-    .field('MAX(escola.ano_censo)', 'end_year')
-    .where('escola.ano_censo > 2014');
+    .field('MAX(escola.ano_censo)', 'end_year');
     next();
 }, query, response('range'));
 
 infrastructureApp.get('/years', cache('15 day'), (req, res, next) => {
-    req.sql.from('escola').
-    field('DISTINCT escola.ano_censo', 'year')
-    .where('escola.ano_censo > 2014');
+    req.sql.from('escola')
+    .field('DISTINCT escola.ano_censo', 'year');
     next();
 }, query, response('years'));
 
-infrastructureApp.get('/source', (req, res, next) => {
+infrastructureApp.get('/source', cache('15 day'), (req, res, next) => {
     req.sql.from('fonte')
     .field('fonte', 'source')
     .where('tabela = \'escola\'');
@@ -56,7 +52,7 @@ infrastructureApp.get('/location', cache('15 day'), (req, res, next) => {
     next();
 }, response('location'));
 
-infrastructureApp.get('/location_detailed', (req, res, next) => {
+infrastructureApp.get('/location_detailed', cache('15 day'), (req, res, next) => {
     req.result = [
         {id: 1, name: "Urbana"},
         {id: 2, name: "Rural"},
@@ -68,7 +64,7 @@ infrastructureApp.get('/location_detailed', (req, res, next) => {
     next();
 }, response('location_detailed'));
 
-infrastructureApp.get('/adm_dependency', (req, res, next) => {
+infrastructureApp.get('/adm_dependency', cache('15 day'), (req, res, next) => {
     req.sql.from('dependencia_adm')
     .field('id')
     .field('nome', 'name')
@@ -255,7 +251,7 @@ function matchQueries(queryTotal, queryPartial) {
     return match;
 }
 
-infrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
+infrastructureApp.get('/', rqf.parse(), rqf.build(), cache('15 day'), (req, res, next) => {
     req.querySet = [];
     req.queryIndex = {};
 
-- 
GitLab