So a week ago I decided to revisit a FF app that I was working on last year. So I had to switch it to v2. I followed the steps in this video https://youtu.be/HfA2f-8m2ms?si=-35j2R3n4vXj4Tpw
... and created 'subscribe' and 'unsubscribe' Custom Actions, which listens to 'all' of one table's changes in realtime. All is well, until Supabase notified me that in just 2 days I've exceeded their 2,000,000 Realtime Messages per month quota (and I'm the only user as the app is still in development). Upgrading to their "Pro" plan with 5,000,000 quota is not gonna do any good either, when you're clocking in 765,000 Realtime Messages per day :)
Most of my 'Realtime' comes from a single table which has 30 columns (but only 7 columns are really being updated in realtime from external API), and the table has circa 800 rows (but only 1-to-5 of them are being updated in realtime at any one time; for example I don't need realtime updates on rows that are older than today). Is there a way to limit the number of Columns that my FF app is listening to by explicitly naming those columns, instead of just declaring 'PostgresChangeEvent.all'??? And is there a way to limit the number of Rows that my FF is subscribing to based on 'status' value or 'date' value???
These the 2 Custom Actions 'subscribe' and 'unsubscribe' that I got from that video:
import 'package:supabase_flutter/supabase_flutter.dart';
/// Subscribes to a specified table in Supabase to receive real-time updates.
///
/// [table]: The name of the table to monitor in the Supabase database.
/// [callbackAction]: A callback function to execute when a change occurs in the table.
Future<void> subscribe(String table, Future Function() callbackAction) async {
// Accessing the Supabase client and subscribing to a specific channel.
// The channel corresponds to the specified table, indicated by 'public:$table'.
// This is where we listen for real-time updates from the table.
SupaFlow.client
.channel('public:$table')
// Setting up an event listener on the channel.
// It listens for any Postgres changes (inserts, updates, deletes, etc.),
// specifically on the 'public' schema of the given table.
.onPostgresChanges(
event: PostgresChangeEvent.all,
schema: 'public',
table: table,
callback: (PostgresChangePayload payload) async {
// Defining the action to take when an update is detected.
// The function 'callbackAction' is called in response to these changes.
await callbackAction();
},
)
// Finalizing the subscription to start listening for the events.
.subscribe();
}
....and the 'unsubscribe' custom action:
import 'package:supabase_flutter/supabase_flutter.dart';
/// Unsubscribes from a previously established real-time connection to a specified table in Supabase.
///
/// [table]: The name of the table from which to disconnect in the Supabase database.
Future<void> unsubscribe(String table) async {
// Accessing the Supabase client and the specific channel for the table.
// The channel is identified by 'public:$table', corresponding to the table we want to unsubscribe from.
final channel = SupaFlow.client.channel('public:$table');
// Unsubscribing from the channel.
// This stops the real-time updates and event listening from the specified table.
await channel.unsubscribe();
}
While going through Supabase logs, I have also found this anomaly, which I believe is somehow related:
Can someone please help make sense what's going on???