nook24 / statusengine

New PHP based MySQL Backend for Naemon and Nagios 4 + responsive web frontend
https://statusengine.org/
GNU General Public License v2.0
16 stars 8 forks source link

truncate tables #19

Closed nook24 closed 8 years ago

nook24 commented 8 years ago

The query that CakePHP builds to truncate the tables is not that good because it is using IN($ALL_IDS)

DELETE `Command` FROM `naemon`.`naemon_commands` AS `Command`   WHERE `Command`.`command_id` IN (1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219)

Solution: Replace with TRUNCATE TABLE ...

nook24 commented 8 years ago

Befor:

62 Query     DELETE `Command` FROM `naemon`.`naemon_commands` AS `Command`   WHERE `Command`.`command_id` IN (1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1
210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219)
62 Query     DELETE `Timeperiod` FROM `naemon`.`naemon_timeperiods` AS `Timeperiod`   WHERE `Timeperiod`.`timeperiod_id` IN (221, 222, 223, 224, 225)
62 Query     DELETE `Timerange` FROM `naemon`.`naemon_timeperiod_timeranges` AS `Timerange`   WHERE `Timerange`.`timeperiod_timerange_id` IN (837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855)
62 Query     DELETE `Contact` FROM `naemon`.`naemon_contacts` AS `Contact`   WHERE `Contact`.`contact_id` = (45)
62 Query     DELETE `Contactgroup` FROM `naemon`.`naemon_contactgroups` AS `Contactgroup`   WHERE `Contactgroup`.`contactgroup_id` = (45)
62 Query     DELETE `Contactgroupmember` FROM `naemon`.`naemon_contactgroup_members` AS `Contactgroupmember`   WHERE `Contactgroupmember`.`contactgroup_member_id` = (45)
62 Query     DELETE `Host` FROM `naemon`.`naemon_hosts` AS `Host`   WHERE `Host`.`host_id` IN (156, 157, 158, 159)
62 Query     DELETE `Hostcontactgroup` FROM `naemon`.`naemon_host_contactgroups` AS `Hostcontactgroup`   WHERE `Hostcontactgroup`.`host_contactgroup_id` IN (156, 157, 158, 159)
62 Query     DELETE `Hostgroup` FROM `naemon`.`naemon_hostgroups` AS `Hostgroup`   WHERE `Hostgroup`.`hostgroup_id` IN (156, 157, 158, 159)
62 Query     DELETE `Hostgroupmember` FROM `naemon`.`naemon_hostgroup_members` AS `Hostgroupmember`   WHERE `Hostgroupmember`.`hostgroup_member_id` IN (156, 157, 158, 159)
62 Query     DELETE `Service` FROM `naemon`.`naemon_services` AS `Service`   WHERE `Service`.`service_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)
62 Query     DELETE `Servicecontactgroup` FROM `naemon`.`naemon_service_contactgroups` AS `Servicecontactgroup`   WHERE `Servicecontactgroup`.`service_contactgroup_id` IN (1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203,
1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218)
62 Query     DELETE `Servicegroup` FROM `naemon`.`naemon_servicegroups` AS `Servicegroup`   WHERE `Servicegroup`.`servicegroup_id` = (35)
62 Query     DELETE `Servicegroupmember` FROM `naemon`.`naemon_servicegroup_members` AS `Servicegroupmember`   WHERE `Servicegroupmember`.`servicegroup_member_id` IN (69, 70)
62 Query     DELETE `Contactstatus` FROM `naemon`.`naemon_contactstatus` AS `Contactstatus`   WHERE `Contactstatus`.`contactstatus_id` = (43)
62 Query     DELETE `Contactnotificationcommand` FROM `naemon`.`naemon_contact_notificationcommands` AS `Contactnotificationcommand`   WHERE `Contactnotificationcommand`.`contact_notificationcommand_id` IN (89, 90)
62 Query     DELETE `Configfile` FROM `naemon`.`naemon_configfiles` AS `Configfile`   WHERE `Configfile`.`configfile_id` = (9)
62 Query     DELETE `Configvariable` FROM `naemon`.`naemon_configfilevariables` AS `Configvariable`   WHERE `Configvariable`.`configfilevariable_id` IN (753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 
771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 82
3, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846)

Now:

138 Query     TRUNCATE `naemon`.`naemon_commands`
138 Query     TRUNCATE `naemon`.`naemon_timeperiods`
138 Query     TRUNCATE `naemon`.`naemon_timeperiod_timeranges`
138 Query     TRUNCATE `naemon`.`naemon_contacts`
138 Query     TRUNCATE `naemon`.`naemon_contactgroups`
138 Query     TRUNCATE `naemon`.`naemon_contactgroup_members`
138 Query     TRUNCATE `naemon`.`naemon_hosts`
138 Query     TRUNCATE `naemon`.`naemon_host_parenthosts`
138 Query     TRUNCATE `naemon`.`naemon_host_contactgroups`
138 Query     TRUNCATE `naemon`.`naemon_host_contacts`
138 Query     TRUNCATE `naemon`.`naemon_customvariables`
138 Query     TRUNCATE `naemon`.`naemon_hostgroups`
138 Query     TRUNCATE `naemon`.`naemon_hostgroup_members`
138 Query     TRUNCATE `naemon`.`naemon_services`
138 Query     TRUNCATE `naemon`.`naemon_service_contactgroups`
138 Query     TRUNCATE `naemon`.`naemon_service_contacts`
138 Query     TRUNCATE `naemon`.`naemon_service_parentservices`
138 Query     TRUNCATE `naemon`.`naemon_servicegroups`
138 Query     TRUNCATE `naemon`.`naemon_servicegroup_members`
138 Query     TRUNCATE `naemon`.`naemon_contactstatus`
138 Query     TRUNCATE `naemon`.`naemon_contact_notificationcommands`
138 Query     TRUNCATE `naemon`.`naemon_contact_addresses`
138 Query     TRUNCATE `naemon`.`naemon_hostescalations`
138 Query     TRUNCATE `naemon`.`naemon_hostescalation_contacts`
138 Query     TRUNCATE `naemon`.`naemon_hostescalation_contactgroups`
138 Query     TRUNCATE `naemon`.`naemon_serviceescalations`
138 Query     TRUNCATE `naemon`.`naemon_serviceescalation_contacts`
138 Query     TRUNCATE `naemon`.`naemon_serviceescalation_contactgroups`
138 Query     TRUNCATE `naemon`.`naemon_hostdependencies`
138 Query     TRUNCATE `naemon`.`naemon_servicedependencies`
138 Query     TRUNCATE `naemon`.`naemon_systemcommands`
138 Query     TRUNCATE `naemon`.`naemon_configfiles`
138 Query     TRUNCATE `naemon`.`naemon_configfilevariables