2 Replies Latest reply on Dec 23, 2013 9:09 AM by Steve Gardner

    RhomSource last_inserted_size same for consecutive Syncs

    Steve Gardner

      I have a rhoconnect application which syncs on logon, as well as at scheduled intervals afterwards.
      In the sync_notify controller that we call for all successful syncs there is some simple logic to check if any new data was inserted.  If there is new data we update the screen, but if there isn't we don't bother.
      However when a user logs in the first two syncs always show the same value for last_inserted_size. (Ie if there are 3 rows on login, the next sync will also insert 3 rows).  After the second sync all is well again and the last_inserted_size returns 0 until data is created on the server.

       

      The last_sync_success is returning true for all syncs, and the last_updated value is different, so I can't understand why the second sync doesn't 0 for the last_inserted size.

      Is my understanding of what last_inserted_size shows wrong?

       

      The relevant code is:

       

      def login_callback

       

          errCode = @params['error_code'].to_i

          if errCode == 0

            WebView.execute_js("ToggleNotificationIcons('Syncing', true)")

            SyncEngine.set_notification(-1, "/app/Settings/sync_notify", '')

            SyncEngine.dosync    

            WebView.navigate ( url_for :controller => :Route, :action => :index )

          else

              #Non relevant error handling removed.

          end 

        end

       

      def do_async_sync

          WebView.execute_js("ToggleNotificationIcons('Syncing', true)")

          SyncEngine.set_notification(-1, "/app/Settings/sync_notify", '')

          SyncEngine.dosync

        end

       

      def sync_notify

          WebView.execute_js("ToggleNotificationIcons('Syncing', true)")

            status = @params['status'] ? @params['status'] : ""

            # un-comment to show a debug status pop-up

       

            if status == "in_progress"    

              # do nothing

            elsif status == "complete"

            begin

              @route_source = Rhom::RhomSource.find('Route')

              @stop_source = Rhom::RhomSource.find('Stop')

       

             # Check if any changes have been made to the Stops  model and reload page if required - this is being called for consecutive syncs after login, but seems to work after that.

             if  @route_source.last_inserted_size > 0 || @route_source.last_deleted_size > 0 || @stop_source.last_inserted_size > 0 || @stop_source.last_deleted_size > 0 then

               SyncEngine.clear_notification(-1)

               WebView.navigate ( url_for :controller => :Route, :action => :index )

             end

           rescue Exception => e

             RhoLog.error("Settings.sync_notify:\t","#{e.message} \n\t#{e.backtrace.join("\n\t")}")

           end