@@ -367,6 +367,7 @@ export async function updateOrganization(
367367 qe : QueryExecutor ,
368368 organizationId : string ,
369369 data : Partial < IDbOrganizationInput > ,
370+ throttleUpdatedAt = false ,
370371) : Promise < string | null > {
371372 const columns = Object . keys ( data )
372373 if ( columns . length === 0 ) {
@@ -376,9 +377,13 @@ export async function updateOrganization(
376377 const updatedAt = new Date ( )
377378 columns . push ( 'updatedAt' )
378379
380+ const updatedAtExpr = throttleUpdatedAt
381+ ? `CASE WHEN "updatedAt" < now() - interval '30 minutes' THEN $(updatedAt) ELSE "updatedAt" END`
382+ : `$(updatedAt)`
383+
379384 const query = `
380385 update organizations set
381- ${ columns . map ( ( c ) => `"${ c } " = $(${ c } )` ) . join ( ',\n' ) }
386+ ${ columns . map ( ( c ) => `"${ c } " = ${ c === 'updatedAt' ? updatedAtExpr : `$ (${ c } )` } ` ) . join ( ',\n' ) }
382387 where id = $(organizationId)
383388 returning id;
384389 `
@@ -443,6 +448,7 @@ export async function findOrCreateOrganization(
443448 source : string ,
444449 data : IOrganization ,
445450 integrationId ?: string ,
451+ throttleUpdatedAt = false ,
446452) : Promise < string | undefined > {
447453 const verifiedIdentities = data . identities ? data . identities . filter ( ( i ) => i . verified ) : [ ]
448454
@@ -524,7 +530,8 @@ export async function findOrCreateOrganization(
524530 if ( Object . keys ( processed . organization ) . length > 0 ) {
525531 log . info ( { orgId : existing . id } , `Updating organization!` )
526532 await logExecutionTimeV2 (
527- async ( ) => updateOrganization ( qe , existing . id , processed . organization ) ,
533+ async ( ) =>
534+ updateOrganization ( qe , existing . id , processed . organization , throttleUpdatedAt ) ,
528535 log ,
529536 'organizationService -> findOrCreateOrganization -> updateOrganization' ,
530537 )
0 commit comments