Skip to content

Comments

[WEB-2816] fix: Sync issues and workspace data when the issue properties are deleted#6165

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
fix-local-sync
Dec 6, 2024
Merged

[WEB-2816] fix: Sync issues and workspace data when the issue properties are deleted#6165
sriramveeraghanta merged 1 commit intopreviewfrom
fix-local-sync

Conversation

@SatishGandham
Copy link
Contributor

@SatishGandham SatishGandham commented Dec 6, 2024

  • Update getIssues call to handle getting issues from workspace when no project ID is present.
  • Sync deleted issues locally.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced synchronization for deleted entities (labels, modules, cycles, states) to ensure associated issues are updated accordingly when these entities are deleted.
  • Bug Fixes

    • Improved error handling in issue retrieval to prevent unnecessary server calls when no project ID is provided.
  • Documentation

    • Updated internal documentation to reflect the new synchronization methods for deleted entities.

These changes improve data integrity and user experience by ensuring that the application remains consistent when managing workspace entities.

…modules/cycles etc are deleted from the project
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes in this pull request primarily enhance the control flow and error handling of the getIssues method in the Storage class, and introduce new synchronization functions for managing deleted entities in the database. The modifications ensure that issues are only fetched when appropriate conditions are met, and that deleted entities are properly handled across various stores, including cycles, labels, modules, and states. Additionally, improvements to SQL query construction for filtering by project ID are implemented to enhance flexibility.

Changes

File Path Change Summary
web/core/local-db/storage.sqlite.ts Modified getIssues method to add conditional logic for handling cases without projectId. Enhanced error handling by preventing unnecessary server calls when the local database is not ready.
web/core/local-db/utils/load-workspace.ts Added functions for synchronizing deleted entities: syncLabels, syncModules, syncCycles, syncStates, syncMembers, along with their respective syncIssuesWithDeleted* functions. Updated loadWorkSpaceData to call these synchronization functions after fetching workspace data.
web/core/local-db/utils/query-constructor.ts Updated issueFilterQueryConstructor to conditionally append projectId to the WHERE clause, defaulting to WHERE 1=1 if not provided.
web/core/local-db/utils/query.utils.ts Modified getFilteredRowsForGrouping to initialize the WHERE clause with 1=1 and conditionally append projectId.
web/core/store/cycle.store.ts Added import for syncIssuesWithDeletedCycles and integrated it into the deleteCycle method to synchronize issues related to deleted cycles.
web/core/store/label.store.ts Added import for syncIssuesWithDeletedLabels and called it in the deleteLabel method to synchronize issues related to deleted labels.
web/core/store/module.store.ts Added import for syncIssuesWithDeletedModules and integrated it into the deleteModule method for synchronizing issues related to deleted modules.
web/core/store/state.store.ts Added import for syncIssuesWithDeletedStates and updated the deleteState method to synchronize issues related to deleted states, ensuring proper MobX state management.

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend, 🧹chore

Suggested reviewers

  • rahulramesha
  • sriramveeraghanta

Poem

In the burrow where the data flows,
Changes made to help it grow.
With cycles, labels, all in sync,
No more errors, let’s all think!
A hop, a skip, to fetch with glee,
Robust and ready, just wait and see! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Outside diff range and nitpick comments (3)
web/core/local-db/utils/load-workspace.ts (1)

108-227: Refactor Synchronization Functions to Reduce Duplication

The functions syncLabels, syncModules, syncCycles, syncStates, and syncMembers share similar logic for synchronizing deleted entities. Consider refactoring these into a generic function to enhance maintainability and reduce code duplication.

Suggested Refactor:

Create a generic synchronization function:

const syncEntities = async (
  entityName: string,
  currentEntities: any[],
  tableName: string,
  issueKey: string,
  updateIssueField: string
) => {
  const currentIdList = currentEntities.map((entity: any) => entity.id);
  const existingEntities = await persistence.db.exec(`SELECT id FROM ${tableName};`);
  const existingIdList = existingEntities.map((entity: any) => entity.id);
  const deletedIds = difference(existingIdList, currentIdList);
  await syncIssuesWithDeletedEntities(deletedIds as string[], issueKey, updateIssueField);
};

And a generic syncIssuesWithDeletedEntities function:

const syncIssuesWithDeletedEntities = async (
  deletedIds: string[],
  issueKey: string,
  updateIssueField: string
) => {
  if (!deletedIds.length) {
    return;
  }
  const issues = await persistence.getIssues("", "", { [issueKey]: deletedIds.join(","), cursor: "10000:0:0" }, {});
  if (issues?.results && Array.isArray(issues.results)) {
    const promises = issues.results.map(async (issue: TIssue) => {
      const updatedIssue = {
        ...issue,
        [updateIssueField]: Array.isArray(issue[updateIssueField])
          ? issue[updateIssueField].filter((id: string) => !deletedIds.includes(id))
          : null,
        is_local_update: 1,
      };
      updateIssue(updatedIssue);
    });
    await Promise.all(promises);
  }
};

Then call this generic function for each entity type.

web/core/store/label.store.ts (1)

279-279: Handle Asynchronous Operation in deleteLabel

After deleting a label and removing it from labelMap, consider awaiting the syncIssuesWithDeletedLabels function to ensure issues are properly synchronized before proceeding.

Suggested Change:

- syncIssuesWithDeletedLabels([labelId]);
+ await syncIssuesWithDeletedLabels([labelId]);

This ensures that the synchronization completes before the method finishes execution.

web/core/store/state.store.ts (1)

232-232: Await Synchronization in deleteState

In the deleteState method, consider awaiting the syncIssuesWithDeletedStates function to ensure that issues are synchronized after the state is deleted.

Suggested Change:

- syncIssuesWithDeletedStates([stateId]);
+ await syncIssuesWithDeletedStates([stateId]);

This ensures proper sequencing of asynchronous operations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b1c340b and 84ff079.

📒 Files selected for processing (8)
  • web/core/local-db/storage.sqlite.ts (1 hunks)
  • web/core/local-db/utils/load-workspace.ts (4 hunks)
  • web/core/local-db/utils/query-constructor.ts (1 hunks)
  • web/core/local-db/utils/query.utils.ts (2 hunks)
  • web/core/store/cycle.store.ts (2 hunks)
  • web/core/store/label.store.ts (2 hunks)
  • web/core/store/module.store.ts (2 hunks)
  • web/core/store/state.store.ts (2 hunks)
🔇 Additional comments (3)
web/core/local-db/storage.sqlite.ts (1)

297-304: Improved error handling for projectId-less requests

The additional conditional logic efficiently handles cases where projectId is not provided, preventing unnecessary server calls and improving the overall performance of the application.

web/core/store/module.store.ts (1)

13-13: Enhanced data consistency with issue synchronization

The addition of syncIssuesWithDeletedModules ensures proper synchronization of issues when modules are deleted, maintaining data consistency across the application. This follows the established pattern used for other entities like cycles, labels, and states.

Also applies to: 442-442

web/core/store/cycle.store.ts (1)

23-23: Consistent implementation of issue synchronization

The addition of syncIssuesWithDeletedCycles aligns with the application's synchronization strategy, ensuring proper cleanup of issue references when cycles are deleted. This implementation maintains consistency with other stores like modules, labels, and states.

Also applies to: 679-679

@sriramveeraghanta sriramveeraghanta merged commit 4499a5f into preview Dec 6, 2024
@sriramveeraghanta sriramveeraghanta deleted the fix-local-sync branch December 6, 2024 10:57
@coderabbitai coderabbitai bot mentioned this pull request Jan 17, 2025
1 task
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

Successfully merging this pull request may close these issues.

2 participants