/** * Handles any index rebuild requirements as a result of new or updated records, e.g. in * samples or occurrences. Also handles joining of occurrence_associations to the * correct records */ private function postProcess() { if (class_exists('cache_builder')) { if (!empty(self::$changedRecords['insert']['occurrence'])) { cache_builder::insert($this->db, 'occurrences', self::$changedRecords['insert']['occurrence']); } if (!empty(self::$changedRecords['update']['occurrence'])) { cache_builder::update($this->db, 'occurrences', self::$changedRecords['update']['occurrence']); } if (!empty(self::$changedRecords['delete']['occurrence'])) { cache_builder::delete($this->db, 'occurrences', self::$changedRecords['delete']['occurrence']); } $samples = array(); if (!empty(self::$changedRecords['insert']['sample'])) { $samples = self::$changedRecords['insert']['sample']; } if (!empty(self::$changedRecords['update']['sample'])) { $samples += self::$changedRecords['update']['sample']; } if (!empty($samples)) { postgreSQL::insertMapSquaresForSamples($samples, 1000, $this->db); postgreSQL::insertMapSquaresForSamples($samples, 2000, $this->db); postgreSQL::insertMapSquaresForSamples($samples, 10000, $this->db); } else { // might be directly inserting an occurrence. No need to do this if inserting a sample, as the above code does the // occurrences in bulk. $occurrences = array(); if (!empty(self::$changedRecords['insert']['occurrence'])) { $occurrences = self::$changedRecords['insert']['occurrence']; } if (!empty(self::$changedRecords['update']['occurrence'])) { $occurrences += self::$changedRecords['update']['occurrence']; } if (!empty($occurrences)) { postgreSQL::insertMapSquaresForOccurrences($occurrences, 1000, $this->db); postgreSQL::insertMapSquaresForOccurrences($occurrences, 2000, $this->db); postgreSQL::insertMapSquaresForOccurrences($occurrences, 10000, $this->db); } } } if (!empty(self::$changedRecords['insert']['occurrence_association'])) { // We've got some associations between occurrences that could not have the to_occurrence_id // foreign key filled in yet, since the occurrence referred to did not exist at the time of // saving foreach (Occurrence_association_Model::$to_occurrence_id_pointers as $associationId => $pointer) { if (!empty($this->dynamicRowIdReferences["occurrence:{$pointer}"])) { $this->db->from('occurrence_associations')->set('to_occurrence_id', $this->dynamicRowIdReferences["occurrence:{$pointer}"])->where('id', $associationId)->update(); } } } }
/** * Handles any index rebuild requirements as a result of new or updated records, e.g. in * samples or occurrences. */ private function postProcess() { if (class_exists('cache_builder')) { if (!empty(self::$changedRecords['insert']['occurrence'])) { cache_builder::insert($this->db, 'occurrences', self::$changedRecords['insert']['occurrence']); } if (!empty(self::$changedRecords['update']['occurrence'])) { cache_builder::update($this->db, 'occurrences', self::$changedRecords['update']['occurrence']); } if (!empty(self::$changedRecords['delete']['occurrence'])) { cache_builder::delete($this->db, 'occurrences', self::$changedRecords['delete']['occurrence']); } $samples = array(); if (!empty(self::$changedRecords['insert']['sample'])) { $samples = self::$changedRecords['insert']['sample']; } if (!empty(self::$changedRecords['update']['sample'])) { $samples += self::$changedRecords['update']['sample']; } if (!empty($samples)) { postgreSQL::insertMapSquaresForSamples($samples, 1000, $this->db); postgreSQL::insertMapSquaresForSamples($samples, 2000, $this->db); postgreSQL::insertMapSquaresForSamples($samples, 10000, $this->db); } else { // might be directly inserting an occurrence. No need to do this if inserting a sample, as the above code does the // occurrences in bulk. $occurrences = array(); if (!empty(self::$changedRecords['insert']['occurrence'])) { $occurrences = self::$changedRecords['insert']['occurrence']; } if (!empty(self::$changedRecords['update']['occurrence'])) { $occurrences += self::$changedRecords['update']['occurrence']; } if (!empty($occurrences)) { postgreSQL::insertMapSquaresForOccurrences($occurrences, 1000, $this->db); postgreSQL::insertMapSquaresForOccurrences($occurrences, 2000, $this->db); postgreSQL::insertMapSquaresForOccurrences($occurrences, 10000, $this->db); } } } }