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

feat: Add cleanRelatedContacts service #1019

Merged
merged 1 commit into from
Nov 14, 2024
Merged

feat: Add cleanRelatedContacts service #1019

merged 1 commit into from
Nov 14, 2024

Conversation

Merkur39
Copy link
Member

When you delete a contact, this service deletes any relationships it may have had with other contacts.

Copy link

bundlemon bot commented Nov 13, 2024

BundleMon

Files added (1)
Status Path Size Limits
services/cleanRelatedContacts/contacts.js
+304.91KB -
Files updated (3)
Status Path Size Limits
services/autoDefineLabels/contacts.js
305.54KB (+26B +0.01%) -
services/keepIndexFullNameAndDisplayNameUpToD
ate/contacts.js
305.48KB (+26B +0.01%) -
app/contacts.(hash).js
285.39KB (+25B +0.01%) -
Unchanged files (4)
Status Path Size Limits
vendors/contacts.(hash).js
926.52KB -
intents/contacts.(hash).js
28.33KB -
app-contacts.(hash).min.css
27.08KB -
img/icon.(hash).svg
454B -

Total files change +304.98KB +16.23%

Groups updated (1)
Status Path Size Limits
**/*.js
2.11MB (+304.98KB +16.47%) -
Unchanged groups (2)
Status Path Size Limits
**/*.css
83.72KB -
img/.
454B -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link
Contributor

@zatteo zatteo left a comment

Choose a reason for hiding this comment

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

Maybe another review from @JF-Cozy or @paultranvan because I'm not familiar with services and it's about deletion so sensitive ?

But looks good from my view.

Copy link
Contributor

@JF-Cozy JF-Cozy left a comment

Choose a reason for hiding this comment

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

on manipule de la data ici, c'est typiquement le cas à tester correctement (sujet du /alpha) perso je mettrai ça derrière un flag

import { DOCTYPE_CONTACTS } from '../helpers/doctypes'

export const cleanRelatedContactsService = async (client, contactDeletedId) => {
const allContacts = await client.queryAll(Q(DOCTYPE_CONTACTS))
Copy link
Contributor

Choose a reason for hiding this comment

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

petite interrogation sur await client.queryAll(Q(DOCTYPE_CONTACTS)) est-ce une bonne manière de faire ? @paultranvan

Copy link
Member Author

Choose a reason for hiding this comment

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

En m'inspirant d'une query existante, ceci serait sans doute plus pertinent.

Q(DOCTYPE_CONTACTS)
      .where({
        relationships: {
          related: {
            data: {
              $elemMatch: {
                _id: contactDeletedId,
                _type: DOCTYPE_CONTACTS
              }
            }
          }
        }
      })
      .indexFields(['relationships.related.data'])
      .limitBy(1000)

Copy link
Contributor

Choose a reason for hiding this comment

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

est-ce une bonne manière de faire ?

On est dans un service, donc moins contraint par la pagination que sur une app. Ceci étant dit, ça ne nous absoud pas de ne requêter que ce qui est nécessaire.
Cf #1019 (comment) pour la requête

Copy link
Member Author

Choose a reason for hiding this comment

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

Vu ensemble, nous allons terminer prochainement cette fonctionnalité de relation entre contact, qui devrait simplifier le besoin ici.
Le temps de, je vais juste ajouter un commentaire pour ne pas oublier de repasser sur cette query.

src/helpers/cleanRelatedContactsService.js Show resolved Hide resolved
@Merkur39 Merkur39 force-pushed the feat/ver-1080 branch 2 times, most recently from eb657de to b80f91f Compare November 13, 2024 14:41
data: {
$elemMatch: {
_id: contactDeletedId,
_type: DOCTYPE_CONTACTS
Copy link
Contributor

@paultranvan paultranvan Nov 13, 2024

Choose a reason for hiding this comment

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

This elemMatch operator is to avoid when possible, because it will force an index full scan.
But why not simply use the include dsl ?

Q(DOCTYPE_CONTACTS).include('related')
``

Copy link
Contributor

Choose a reason for hiding this comment

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

On afterthought, using this query will also make a full-scan, and then query all the the relationships, so not good either...

When you delete a contact, this service deletes any
relationships it may have had with other contacts.
@Merkur39 Merkur39 merged commit 56fd340 into master Nov 14, 2024
2 checks passed
@Merkur39 Merkur39 deleted the feat/ver-1080 branch November 14, 2024 08:44
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.

4 participants