-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: respect DATABASE_SAVE_DATA_CONTACTS in contact updates #2250
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
Open
gabrielmouallem
wants to merge
2
commits into
EvolutionAPI:main
Choose a base branch
from
gabrielmouallem:fix/respect-database-save-data-contacts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: respect DATABASE_SAVE_DATA_CONTACTS in contact updates #2250
gabrielmouallem
wants to merge
2
commits into
EvolutionAPI:main
from
gabrielmouallem:fix/respect-database-save-data-contacts
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Reviewer's GuideConditionally persist WhatsApp contact data based on DATABASE.SAVE_DATA.CONTACTS while leaving webhook and Chatwoot integrations intact, and make minor formatting adjustments. Sequence diagram for conditional WhatsApp contact persistence based on DATABASE.SAVE_DATA.CONTACTSsequenceDiagram
actor "WhatsApp" as WhatsApp
participant "BaileysStartupService" as Baileys
participant "ConfigService" as Config
participant "PrismaRepository (Database)" as Prisma
participant "Webhook consumer" as Webhook
participant "Chatwoot integration" as Chatwoot
"WhatsApp" ->> "BaileysStartupService": "Contacts update event with contacts list"
activate "BaileysStartupService"
"BaileysStartupService" ->> "Webhook consumer": "sendDataWebhook(\"CONTACTS_UPDATE\", contacts)"
loop "For each updated contact"
"BaileysStartupService" ->> "ConfigService": "get(\"DATABASE\").SAVE_DATA.CONTACTS"
"ConfigService" -->> "BaileysStartupService": "Boolean flag"
alt "SAVE_DATA.CONTACTS is true"
"BaileysStartupService" ->> "PrismaRepository (Database)": "contact.updateMany({ where: { remoteJid, instanceId }, data: { profilePicUrl } })"
else "SAVE_DATA.CONTACTS is false"
"BaileysStartupService" --x "PrismaRepository (Database)": "Skip contact.updateMany"
end
"BaileysStartupService" ->> "ConfigService": "get(\"CHATWOOT\").ENABLED"
"ConfigService" -->> "BaileysStartupService": "Boolean flag"
alt "CHATWOOT is enabled and localChatwoot.enabled"
"BaileysStartupService" ->> "Chatwoot integration": "Sync contact data (e.g., profile picture)"
else "CHATWOOT disabled"
"BaileysStartupService" --x "Chatwoot integration": "Skip Chatwoot sync"
end
end
deactivate "BaileysStartupService"
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- In the updatedContacts.map(...) block, the Prisma updateMany call is assigned to a variable but never awaited or returned from the async callback, so the database updates will not actually be executed; consider returning the update promise (or collecting them separately) so Promise.all awaits them.
- You repeatedly call this.configService.get(...) inside per-contact loops; consider caching DATABASE.SAVE_DATA.CONTACTS (and similar flags) in a local constant before the loop to avoid redundant lookups on each iteration.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the updatedContacts.map(...) block, the Prisma updateMany call is assigned to a variable but never awaited or returned from the async callback, so the database updates will not actually be executed; consider returning the update promise (or collecting them separately) so Promise.all awaits them.
- You repeatedly call this.configService.get(...) inside per-contact loops; consider caching DATABASE.SAVE_DATA.CONTACTS (and similar flags) in a local constant before the loop to avoid redundant lookups on each iteration.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:842-845` </location>
<code_context>
- where: { remoteJid: contact.remoteJid, instanceId: this.instanceId },
- data: { profilePicUrl: contact.profilePicUrl },
- });
+ let update;
+ if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS) {
+ update = this.prismaRepository.contact.updateMany({
+ where: { remoteJid: contact.remoteJid, instanceId: this.instanceId },
+ data: { profilePicUrl: contact.profilePicUrl },
+ });
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The `update` variable is never used or awaited inside the async mapper, which can hide DB errors and make the intent unclear.
Within `updatedContacts.map(async (contact) => { ... })`, `update` is set to `this.prismaRepository.contact.updateMany(...)` but never awaited or returned. As a result, the DB write runs in the background, errors may be lost, and `Promise.all` does not actually wait for the update to finish. If the write must succeed, either `await this.prismaRepository.contact.updateMany(...)` or `return this.prismaRepository.contact.updateMany(...)` so `Promise.all` awaits it. If it’s intentionally best-effort, remove `let update` and call `void this.prismaRepository.contact.updateMany(...)` to clarify intent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Outdated
Show resolved
Hide resolved
- Added missing conditional checks for `DATABASE_SAVE_DATA_CONTACTS` in `contacts.upsert` and `contacts.update` handlers. - Fixed an issue where profile picture updates were attempting to save to the database even when disabled. - Fixed an unawaited promise in `contacts.upsert` to ensure database operations complete correctly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📋 Description
The
DATABASE_SAVE_DATA_CONTACTSenvironment variable was being ignored in specific parts of thecontacts.upsert(profile picture updates) andcontacts.updatehandlers.This PR adds the missing conditional checks to ensure that contact data is only saved to the database when this configuration is explicitly enabled, maintaining consistency with other
SAVE_DATAflags.🔗 Related Issue
Closes #(issue_number)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
Summary by Sourcery
Respect database configuration flags when processing WhatsApp contact updates to avoid persisting contacts when disabled.
Bug Fixes:
Enhancements: