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

CRM : Handle data when > 6000 rows #3519

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions supabase/functions/crm_sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ serve(async (req) => {
const { token, table, sync } = await req.json();

// Récupère les données de la table au format csv.
const csvResponse = await supabase.from(table).select().csv();
const { error, data, count } = await supabase
.from(table)
.select('*', { count: 'exact' })
.range(0, 4999)
.csv();

let allData = data;

if (count > 5000) {
const { data: dataOver5000 } = await supabase
.from(table)
.select('*')
.range(5000, 9999)
.csv();

allData += '\n' + dataOver5000.replace(/.*\n/, '') /* remove header */;
}

// Envoie les données à Airtable vers l'endpoint sync.
const syncResponse = await fetch(sync, {
Expand All @@ -30,10 +46,17 @@ serve(async (req) => {
Authorization: `Bearer ${token}`,
'Content-Type': 'text/csv',
},
body: csvResponse.data,
body: allData,
});

const { success } = await syncResponse.json();
console.log(
JSON.stringify({
success,
table,
nbOfRows: allData.split('\n').length - 1 /* without header */,
})
);

// Renvoie le statut pour persister dans les logs Supabase.
return new Response(
Expand Down
Loading