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

Speed up unit creation #136

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10,287 changes: 0 additions & 10,287 deletions db snapshots/unee-t_BZFE_v3.10_clean.sql

This file was deleted.

10,294 changes: 0 additions & 10,294 deletions db snapshots/unee-t_BZFE_v3.11_clean.sql

This file was deleted.

10,594 changes: 0 additions & 10,594 deletions db snapshots/unee-t_BZFE_v3.12_clean.sql

This file was deleted.

10,773 changes: 0 additions & 10,773 deletions db snapshots/unee-t_BZFE_v3.13_clean.sql

This file was deleted.

10,880 changes: 0 additions & 10,880 deletions db snapshots/unee-t_BZFE_v3.14_clean.sql

This file was deleted.

10,920 changes: 0 additions & 10,920 deletions db snapshots/unee-t_BZFE_v3.15_clean.sql

This file was deleted.

10,964 changes: 0 additions & 10,964 deletions db snapshots/unee-t_BZFE_v3.16_clean.sql

This file was deleted.

10,984 changes: 0 additions & 10,984 deletions db snapshots/unee-t_BZFE_v3.17_clean.sql

This file was deleted.

11,120 changes: 0 additions & 11,120 deletions db snapshots/unee-t_BZFE_v3.18_clean.sql

This file was deleted.

11,424 changes: 0 additions & 11,424 deletions db snapshots/unee-t_BZFE_v3.19_clean.sql

This file was deleted.

12,071 changes: 0 additions & 12,071 deletions db snapshots/unee-t_BZFE_v3.20_clean.sql

This file was deleted.

12,318 changes: 0 additions & 12,318 deletions db snapshots/unee-t_BZFE_v3.21_clean.sql

This file was deleted.

12,403 changes: 0 additions & 12,403 deletions db snapshots/unee-t_BZFE_v3.22_clean.sql

This file was deleted.

12,488 changes: 0 additions & 12,488 deletions db snapshots/unee-t_BZFE_v3.23_clean.sql

This file was deleted.

12,679 changes: 0 additions & 12,679 deletions db snapshots/unee-t_BZFE_v3.24_clean.sql

This file was deleted.

12,840 changes: 0 additions & 12,840 deletions db snapshots/unee-t_BZFE_v3.25_clean.sql

This file was deleted.

14,038 changes: 0 additions & 14,038 deletions db snapshots/unee-t_BZFE_v3.26_clean.sql

This file was deleted.

14,038 changes: 0 additions & 14,038 deletions db snapshots/unee-t_BZFE_v3.27_clean.sql

This file was deleted.

16,506 changes: 0 additions & 16,506 deletions db snapshots/unee-t_BZFE_v3.28_clean.sql

This file was deleted.

15,967 changes: 0 additions & 15,967 deletions db snapshots/unee-t_BZFE_v3.29_clean.sql

This file was deleted.

15,963 changes: 0 additions & 15,963 deletions db snapshots/unee-t_BZFE_v3.30_clean.sql

This file was deleted.

3,586 changes: 3,586 additions & 0 deletions db upgrade/upgrade_unee-t_v5.37.0_to_v5.38.sql

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

/* Procedure structure for procedure `update_permissions_invited_user` */

DROP PROCEDURE IF EXISTS `update_permissions_invited_user` ;

DELIMITER $$

CREATE PROCEDURE `update_permissions_invited_user`()
SQL SECURITY INVOKER
BEGIN

# We update the `user_group_map` table
# - Create an intermediary table to deduplicate the records in the table `ut_user_group_map_temp`
# - If the record does NOT exists in the table then INSERT new records in the table `user_group_map`
# - If the record DOES exist in the table then update the new records in the table `user_group_map`
#
# We NEED the table `ut_user_group_map_temp` BUT this table should already exist. DO NO re-create it here!!!

# We drop the deduplication table if it exists:
DROP TEMPORARY TABLE IF EXISTS `ut_user_group_map_dedup`;

# We create a table `ut_user_group_map_dedup` to prepare the data we need to insert
CREATE TEMPORARY TABLE `ut_user_group_map_dedup` (
`user_id` MEDIUMINT(9) NOT NULL
, `group_id` MEDIUMINT(9) NOT NULL
, `isbless` TINYINT(4) NOT NULL DEFAULT '0'
, `grant_type` TINYINT(4) NOT NULL DEFAULT '0'
# UNIQUE KEY `user_group_map_dedup_user_id_idx` (`user_id`, `group_id`, `grant_type`, `isbless`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
;

# We insert the de-duplicated record in the table `user_group_map_dedup`
INSERT INTO `ut_user_group_map_dedup`
SELECT `user_id`
, `group_id`
, `isbless`
, `grant_type`
FROM
`ut_user_group_map_temp`
GROUP BY `user_id`
, `group_id`
, `isbless`
, `grant_type`
ORDER BY `user_id` ASC
, `group_id` ASC
;

# We insert the data we need in the `user_group_map` table
INSERT INTO `user_group_map`
SELECT `user_id`
, `group_id`
, `isbless`
, `grant_type`
FROM
`ut_user_group_map_dedup`
# The below code is overkill in this context:
# the Unique Key Constraint makes sure that all records are unique in the table `user_group_map`
ON DUPLICATE KEY UPDATE
`user_id` = `ut_user_group_map_dedup`.`user_id`
, `group_id` = `ut_user_group_map_dedup`.`group_id`
, `isbless` = `ut_user_group_map_dedup`.`isbless`
, `grant_type` = `ut_user_group_map_dedup`.`grant_type`
;

# We drop the temp table as we do not need it anymore
DROP TEMPORARY TABLE IF EXISTS `ut_user_group_map_dedup`;

END $$
DELIMITER ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

/* Procedure structure for procedure `user_in_default_cc_for_cases` */

DROP PROCEDURE IF EXISTS `user_in_default_cc_for_cases` ;

DELIMITER $$

CREATE PROCEDURE `user_in_default_cc_for_cases`()
BEGIN
IF (@user_in_default_cc_for_cases = 1)
THEN

# We record the name of this procedure for future debugging and audit_log
SET @script = 'PROCEDURE - user_in_default_cc_for_cases';
SET @timestamp = NOW();

# We use a temporary table to make sure we do not have duplicates.

# DELETE the temp table if it exists
DROP TEMPORARY TABLE IF EXISTS `ut_temp_component_cc`;

# Re-create the temp table
CREATE TEMPORARY TABLE `ut_temp_component_cc` (
`user_id` MEDIUMINT(9) NOT NULL
, `component_id` MEDIUMINT(9) NOT NULL,
KEY `search_user_id` (`user_id`, `component_id`),
KEY `search_component_id` (`component_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
;

# Add the records that exist in the table component_cc
INSERT INTO `ut_temp_component_cc`
SELECT *
FROM `component_cc`;

# Add the new user rights for the product
INSERT INTO `ut_temp_component_cc`
(user_id
, component_id
)
VALUES
(@bz_user_id, @component_id)
;

# We drop the deduplication table if it exists:
DROP TEMPORARY TABLE IF EXISTS `ut_temp_component_cc_dedup`;

# We create a table `ut_user_group_map_dedup` to prepare the data we need to insert
CREATE TEMPORARY TABLE `ut_temp_component_cc_dedup` (
`user_id` MEDIUMINT(9) NOT NULL
, `component_id` MEDIUMINT(9) NOT NULL
# , UNIQUE KEY `ut_temp_component_cc_dedup_userid_componentid` (`user_id`, `component_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
;

# We insert the de-duplicated record in the table `ut_temp_component_cc_dedup`
INSERT INTO `ut_temp_component_cc_dedup`
SELECT `user_id`
, `component_id`
FROM
`ut_temp_component_cc`
GROUP BY `user_id`
, `component_id`
;

# We insert the new records in the table `component_cc`
INSERT INTO `component_cc`
SELECT `user_id`
, `component_id`
FROM
`ut_temp_component_cc_dedup`
GROUP BY `user_id`
, `component_id`
# The below code is overkill in this context:
# the Unique Key Constraint makes sure that all records are unique in the table `user_group_map`
ON DUPLICATE KEY UPDATE
`user_id` = `ut_temp_component_cc_dedup`.`user_id`
, `component_id` = `ut_temp_component_cc_dedup`.`component_id`
;

# Clean up:
# We drop the deduplication table if it exists:
DROP TEMPORARY TABLE IF EXISTS `ut_temp_component_cc_dedup`;

# We Delete the temp table as we do not need it anymore
DROP TEMPORARY TABLE IF EXISTS `ut_temp_component_cc`;

# Log the actions of the script.
SET @script_log_message = CONCAT('the bz user #'
, @bz_user_id
, ' is one of the copied assignee for the unit #'
, @product_id
, ' when the role '
, @role_user_g_description
, ' (the component #'
, @component_id
, ')'
, ' is chosen'
);

INSERT INTO `ut_script_log`
(`datetime`
, `script`
, `log`
)
VALUES
(NOW(), @script, @script_log_message)
;

# Cleanup the variables for the log messages
SET @script_log_message = NULL;
SET @script = NULL;
END IF ;
END $$
DELIMITER ;