From 47fc67660797445af9fb37ddffe4da4cb0b8e617 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 26 Jun 2018 11:41:08 -0400 Subject: [PATCH] cache last job_event page when not running --- .../features/output/api.events.service.js | 18 +++++++++++++++++- awx/ui/client/features/output/slide.service.js | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/features/output/api.events.service.js b/awx/ui/client/features/output/api.events.service.js index 84c441c3d5..3a4e033cfa 100644 --- a/awx/ui/client/features/output/api.events.service.js +++ b/awx/ui/client/features/output/api.events.service.js @@ -15,9 +15,21 @@ function JobEventsApiService ($http, $q) { this.params = merge(BASE_PARAMS, params); this.state = { count: 0, maxCounter: 0 }; + this.cache = {}; }; - this.fetch = () => this.getLast().then(() => this); + this.clearCache = () => { + Object.keys(this.cache).forEach(key => { + delete this.cache[key]; + }); + }; + + this.fetch = () => this.getLast() + .then(results => { + this.cache.last = results; + + return this; + }); this.getFirst = () => { const page = 1; @@ -61,6 +73,10 @@ function JobEventsApiService ($http, $q) { }; this.getLast = () => { + if (this.cache.last) { + return $q.resolve(this.cache.last); + } + const params = merge(this.params, { page: 1, order_by: `-${ORDER_BY}` }); return $http.get(this.endpoint, { params }) diff --git a/awx/ui/client/features/output/slide.service.js b/awx/ui/client/features/output/slide.service.js index b1614219c5..16551083b7 100644 --- a/awx/ui/client/features/output/slide.service.js +++ b/awx/ui/client/features/output/slide.service.js @@ -102,6 +102,8 @@ function SlidingWindowService ($q) { this.records = {}; this.uuids = {}; this.chain = $q.resolve(); + + api.clearCache(); }; this.pushFront = events => {