pg_net icon indicating copy to clipboard operation
pg_net copied to clipboard

Database Webhooks get fired >1s after record inserted

Open davidfant opened this issue 1 year ago • 4 comments

Bug report

  • [X] I confirm this is a bug with Supabase, not with my own application.
  • [X] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When a record is inserted I have a database webhook trigger that points at a Supabase function. There is always a delay of slightly over 1s between when a record is inserted (record.created_at) and when the trigger is fired. I'm running this locally, so there should be minimal networking overhead

For example:

Record created at: 2024-06-30T10:20:40.036685+00:00
new Date() in supabase function: 2024-06-30T10:20:41.129Z

To Reproduce

  1. Create a table
  2. Set up a database webhook trigger pointing at a Supabase function. console.log both record.created_at and new Date() to see the times
  3. Insert a record into the table

Expected behavior

Webhooks should be fired ~immediately

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS
  • Browser (if applies) -
  • Version of supabase-js: 2.43.4
  • Version of Node.js: v21.1

Additional context

If it's not related to an actual issue in Supabase, please let me know anything I can do to cut down on the latency

davidfant avatar Jun 30 '24 10:06 davidfant

Hi there, thanks for opening. You might need to give some more information here if that is OK.

The firing happens 1 second after you make a call to insert? Or it is 1 second after the insert has happened?

Is the insert a single record, or multiple? Are there any indexes or other constraints on the table?

Does the time decrease once the function has been called a few times (i.e. is it the startup time of the functions causing this or is it the delay from the trigger)

encima avatar Jul 01 '24 07:07 encima

@encima

  1. 1s from whenever the time the database NOW() is run to set the default created_at column value. All DB calls are pretty much instant because I'm running it locally and have an empty database, so that's certainly not taking 1s.
  2. Single record
  3. No indexes but 1 FK
  4. The time is always slightly above 1s, even when I run it 100 times

davidfant avatar Jul 04 '24 21:07 davidfant

@encima @Hallidayo let me know if I can provide any additional details!

davidfant avatar Jul 11 '24 11:07 davidfant

@davidfant - I'll try this out and come back to you.

Hallidayo avatar Jul 11 '24 20:07 Hallidayo