Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - #551 - Auto Clear History #616

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Vishwa-Karthik
Copy link

@Vishwa-Karthik Vishwa-Karthik commented Feb 23, 2025

Foss Hack 2025 - Auto Clear History via WidgetBindingObserver & State Mgmt for Dynamic Clean Up

Team Dart Knight

Relevant PR for Clearing API History

Debug Considerations

  • Enrolled new enum value of 5second for HistoryRentetionPeriod for debugging purposes.
  • The final PR will have clean code

Checklist

  • [✅ ] I have gone through the contributing guide
  • [✅] I have updated my branch and synced it with project main branch before making this PR
  • [✅ ] I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • [✅ ] I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • [✅ ] No, and this is why: please replace this line with details on why tests have not been included

OS on which you have developed and tested the feature?

  • [✅] Android
  • [✅ ] Windows
  • macOS
  • Linux

cc: @ashitaprasad

@Vishwa-Karthik
Copy link
Author

Vishwa-Karthik commented Feb 23, 2025

History Service Implementation for Auto-Clearing API Requests

Team Dart Knight

Do Checkout

Overview

This document outlines the implementation of the autoClearHistory feature in APIDASH to efficiently manage stored API request history while maintaining a smooth user experience across all supported platforms.

Features

Auto-Clear History on App Launch

  • When the app is launched, it automatically clears 50 old API records to prevent excessive local storage usage.

  • This helps in keeping the app responsive and prevents unnecessary memory consumption.

  • Triggered using autoClearHistory() from HistoryServiceImpl.

Dynamic Auto-Clear Trigger (State Management-Based)

  • Uses Riverpod StateNotifier to monitor the API request list dynamically.

  • If the length exceeds 50, the history clearance is automatically triggered, just to avoid heavy duty on app launch.

  • Reason to use State management here is to resist unnecessary local database call because user may keep switching apps/window during development cycle.

Platform-Specific Cleanup Handling

  • For Android & iOS: Uses AppLifecycleState.paused via WidgetsBindingObserver to trigger autoClearHistory() when the app goes to the background.

  • For Windows, macOS, Linux:Uses window_manager to detect app minimize events and trigger cleanup accordingly.

  • Ensures proper handling since AppLifecycleState does not work on desktops.

Batch Deletion Strategy

  • Deleting 50 records at a time minimizes performance issues.

  • Ensures smooth UX by avoiding excessive database transactions.

  • Users can continue adding new requests seamlessly without experiencing lag.

cc: @ashitaprasad

@Vishwa-Karthik Vishwa-Karthik marked this pull request as ready for review February 23, 2025 16:21
@ashitaprasad
Copy link
Member

@ashitaprasad
Copy link
Member

To be reviewed by @DenserMeerkat

@DenserMeerkat
Copy link
Contributor

DenserMeerkat commented Mar 26, 2025

@ashitaprasad

Platforms tested

  • Windows
  • Android

Observation

The auto-clearing works in the platforms tested.
But the history providers are not updated after clearing files hence the deleted history cards are still shown in the UI.

Other Comments

The app.dart now has 2 ConsumerStatefulWidget with WindowListener mixins which feels redundant and can be tidied up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants