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 Request: Support for Change Tokens #184

Open
Ryiguchi opened this issue Dec 12, 2024 · 0 comments
Open

Feature Request: Support for Change Tokens #184

Ryiguchi opened this issue Dec 12, 2024 · 0 comments

Comments

@Ryiguchi
Copy link

Description

I would like to request the implementation of change token support to facilitate efficient and reliable data synchronization.

Change tokens are a robust mechanism for incrementally fetching changes (insertions, updates, and deletions) since the last sync. This would be an incredibly valuable feature for applications that need to interact with large datasets while maintaining synchronization efficiently.

Use Case

Currently, the library requires developers to rely on timestamp-based filtering to fetch new or updated records. While this approach works for basic use cases, it has several limitations:

  • Handling Deletions: Timestamp-based filtering does not track deletions, requiring additional logic or full dataset comparisons to reconcile data.
  • Backdated Data: Records added or updated with backdated timestamps may be missed during synchronization.
  • Efficiency: Fetching data based on timestamps can be less efficient, especially when dealing with large datasets and complex queries.

By supporting change tokens, the library could provide:

  • Incremental data synchronization for all types of changes (insertions, updates, and deletions).
  • Improved performance by reducing redundant data fetching.
  • Enhanced reliability in syncing data states accurately.

Proposed Solution

Implement support for the Health Connect change tokens feature in the react-native-health-connect library. Specifically:

Provide a method (e.g., getChanges) that accepts a ChangeToken and returns the incremental changes since the last sync, along with a new ChangeToken.
Include information about:

  • Inserted records
  • Updated records
  • Deleted records

API Example

const { changes, nextChangeToken } = await getChanges({
  recordType: 'Steps', // Specify the record type
  changeToken: previousChangeToken, // Use the last saved change token
});

// Process changes
changes.forEach(change => {
  if (change.changeType === 'INSERT') {
    // Handle new records
  } else if (change.changeType === 'UPDATE') {
    // Handle updated records
  } else if (change.changeType === 'DELETE') {
    // Handle deleted records
  }
});

// Save the new change token for the next sync
previousChangeToken = nextChangeToken;

Thank you for considering this feature request! This addition would greatly enhance the library's capabilities and make it easier for developers to build performant and reliable health-related applications.

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

No branches or pull requests

1 participant