From d324d141d0d041877b2b56dc6a4b87fa868deefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Mon, 3 Jan 2022 21:53:41 +0800 Subject: [PATCH] fix error --- app/controllers/ruling_buses_controller.rb | 11 +++++++---- app/helpers/ruling_buses_helper.rb | 9 ++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/ruling_buses_controller.rb b/app/controllers/ruling_buses_controller.rb index 55ee4b1..de8fdee 100644 --- a/app/controllers/ruling_buses_controller.rb +++ b/app/controllers/ruling_buses_controller.rb @@ -48,12 +48,15 @@ private cache = RulingBusCache.where(bus_info_id: bus_info_id).first if (cache.nil? || cache.updated_at < @time_thresh) tmp = RulingBusesHelper.get_stop_time(bus_info,@bus_locale) - if cache.nil? - RulingBusCache.create(dict: tmp, bus_info_id: bus_info_id) + if !tmp.nil? + if cache.nil? + RulingBusCache.create(dict: tmp, bus_info_id: bus_info_id) + else + cache.update_attributes(dict: tmp, updated_at: Time.now) + end else - cache.update_attributes(dict: tmp) + tmp = cache.dict end - tmp else tmp = cache.dict end diff --git a/app/helpers/ruling_buses_helper.rb b/app/helpers/ruling_buses_helper.rb index 2a6844c..047779d 100644 --- a/app/helpers/ruling_buses_helper.rb +++ b/app/helpers/ruling_buses_helper.rb @@ -126,6 +126,9 @@ module RulingBusesHelper end.join(' or ') url = "/Bus/EstimatedTimeOfArrival/City/#{city}?$select=Direction,RouteName,NextBusTime&$filter=#{filters}&$format=JSON&$orderby=RouteName/#{locale}" bus_data = JSON.parse(self.get(url).body) + if bus_data.class==Hash + return nil + end if !cache_data_pbus.blank? filters = cache_data_pbus.map do |k,v| ("((StopName/#{locale} eq '#{k[0][locale]}') and Direction eq #{k[2]} and " + @@ -136,7 +139,11 @@ module RulingBusesHelper else pbus_data = [] end - bus_data + pbus_data + if pbus_data.class==Hash + bus_data + else + bus_data + pbus_data + end end def get_input_name