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

Implement queue system to replace actual trigger and make the db faster #429

Closed
riderx opened this issue Oct 19, 2023 · 2 comments · Fixed by #446
Closed

Implement queue system to replace actual trigger and make the db faster #429

riderx opened this issue Oct 19, 2023 · 2 comments · Fixed by #446

Comments

@riderx
Copy link
Contributor

riderx commented Oct 19, 2023

Right now users cannot delete they app because the delete cascade to device table and logs and this table have too much data.

So one idea is to replace the cascade delete by job in a queue:

https://blog.mansueli.com/building-a-queue-system-with-supabase-and-postgresql

All this triggers:

CREATE TRIGGER on_app_stats_create 
AFTER INSERT ON public.app_stats 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_app_stats_create');

CREATE TRIGGER on_app_stats_update 
AFTER UPDATE ON public.app_stats 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_app_stats_update');

CREATE TRIGGER on_channel_create 
AFTER INSERT ON public.channels 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_channel_create');

CREATE TRIGGER on_channel_update 
AFTER UPDATE ON public.channels 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_channel_update');

CREATE TRIGGER on_shared_create 
AFTER INSERT ON public.channel_users 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_shared_create');

CREATE TRIGGER on_user_create 
AFTER INSERT ON public.users 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_user_create');

CREATE TRIGGER on_user_update 
AFTER UPDATE ON public.users 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_user_update');

CREATE TRIGGER on_version_create 
AFTER INSERT ON public.app_versions 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_version_create');

CREATE TRIGGER on_version_update 
AFTER UPDATE ON public.app_versions 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_version_update');

CREATE TRIGGER on_devices_override_update 
AFTER INSERT or UPDATE or DELETE ON public.devices_override 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_device_update');

CREATE TRIGGER on_channel_devices_update 
AFTER INSERT or UPDATE or DELETE ON public.channel_devices 
FOR EACH ROW 
EXECUTE FUNCTION public.trigger_http_post_to_function('on_device_update');

CREATE TRIGGER on_app_delete_sql 
BEFORE DELETE ON apps 
FOR EACH ROW 
EXECUTE PROCEDURE on_app_delete_sql();

CREATE TRIGGER on_app_versions_delete_sql 
BEFORE DELETE ON app_versions 
FOR EACH ROW 
EXECUTE PROCEDURE on_app_version_delete_sql();

CREATE TRIGGER on_device_delete_sql 
BEFORE DELETE ON devices 
FOR EACH ROW 
EXECUTE PROCEDURE on_device_delete_sql();

Have to be evaluated for transfer to queue mode

@WcaleNieWolny
Copy link
Contributor

I will be attempting this

@riderx
Copy link
Contributor Author

riderx commented Oct 19, 2023

Also in the list the generation of stats for user dashboard and billing.
I'm working on a function who can read the current CPU mem usage and prevent the job to run when it's hight usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants