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

feat: add 2 script for clean incremental_sync db #276

Merged
merged 8 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ public function uninstall()
}

/**
* This function allows you to patch bugs that can be found related to "ServiceNotFoundException".
* This function allows you to patch bugs that can be found related to "ServiceNotFoundException".
* It ensures that you have access to the SymfonyContainer, and also that you have access to FO services.
*
* @param string $serviceName
*
* @return mixed
Expand Down
52 changes: 52 additions & 0 deletions sql/tools/clean_incremental_sync.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- Define the name of the database and the quantity desired for the clean
SET @db_name = 'prestashop';
set @quantity_needed = '100000';

-- Retrieve the eventbus_incremental_sync table name with prefix
SET @eventbus_incremental_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_incremental_sync');

-- Retrieve the _eventbus_type_sync table name with prefix
SET @eventbus_type_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_type_sync');

-- enable full-sync for selected shop content
SET @enable_full_sync = CONCAT('
UPDATE ', @eventbus_type_sync_table, '
SET `offset` = 0
fox-john marked this conversation as resolved.
Show resolved Hide resolved
WHERE type IN (
SELECT type
FROM (
SELECT type, COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
) AS subquery
);
');

-- Execute dynamic query
PREPARE enable_full_sync FROM @enable_full_sync;
EXECUTE enable_full_sync;

-- Delete entries with more than X entries of this type (set above via the variable @quantity_needed)
SET @delete_query = CONCAT('
DELETE FROM ', @eventbus_incremental_sync_table, '
WHERE type IN (
SELECT type
FROM (
SELECT type, COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
) AS subquery
);
');

-- Execute dynamic query
PREPARE delete_query FROM @delete_query;
EXECUTE delete_query;
22 changes: 22 additions & 0 deletions sql/tools/count_incremental_sync.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Define the name of the database and the quantity desired for the clean
SET @db_name = 'prestashop';
set @quantity_needed = '100000';

-- Retrieve the eventbus_incremental_sync table name with prefix
SET @eventbus_incremental_sync_table = (SELECT table_name
FROM information_schema.tables
WHERE table_schema = @db_name
AND table_name LIKE '%_eventbus_incremental_sync');

-- Retrieves the input quantity and associated type
SET @get_content_with_extra_counts = CONCAT('
SELECT type,
COUNT(*) as incr_type_count
FROM ', @eventbus_incremental_sync_table, '
GROUP BY type
HAVING COUNT(*) > ', @quantity_needed, '
');

-- Execute dynamic query
PREPARE get_content_with_extra_counts FROM @get_content_with_extra_counts;
EXECUTE get_content_with_extra_counts;
Loading