Skip to content

Commit 6a3b21b

Browse files
committed
optimize static values (same for all rows) and add csv_file id
1 parent 7d003ee commit 6a3b21b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

inc/db/personal.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -174,35 +174,45 @@ public function setProfile($profile)
174174
* High speed row insertion.
175175
*
176176
* @note This is might be very MySQL specifc. Not recomended for normal usage.
177+
* @note We assume `pf_insRecordExtraParse`.
177178
*
178179
* @param array $pv_records Records to be inserted.
179180
* @return int 0 upon error
180181
* @throws Exception If \a pv_tableName was not set.
181182
*/
182-
public function pf_insRecords(&$pv_records)
183+
public function pf_insRecords(&$pv_records, $fileId)
183184
{
184185
if (empty($this->pv_tableName))
185186
{
186187
throw new Exception("Tabel name is empty");
187188
}
188189

190+
// static values
191+
$pv_staticRecord = array();
192+
$pv_staticRecord['csv_file'] = $fileId;
193+
$this->pf_insRecordExtraParse($pv_staticRecord); // Note! Assuming it only adds values.
194+
$pv_staticValues = "";
195+
foreach ($pv_staticRecord as $pv_val)
196+
{
197+
$pv_staticValues .= "'".mysql_real_escape_string($pv_val)."',";
198+
}
199+
$pv_staticValues = rtrim($pv_staticValues, ",");
200+
189201
// Prepare "header" of the INSERT statement
190-
$pv_record = $pv_records[0];
191-
$this->pf_insRecordExtraParse($pv_record);
192-
$pv_ins_sql_arr = $this->pf_getInsSQLArrays($pv_record);
202+
$pv_headerRecord = array_merge($pv_records[0], $pv_staticRecord);
203+
$pv_ins_sql_arr = $this->pf_getInsSQLArrays($pv_headerRecord);
193204
$sql = "INSERT INTO {$this->pv_tableName} {$pv_ins_sql_arr['']['keys']}
194205
VALUES"
195206
;
196207

197208
// Build SQL
198209
foreach($pv_records as &$pv_record) {
199210
$values = "";
200-
$this->pf_insRecordExtraParse($pv_record);
201211
foreach ($pv_record as $pv_val)
202212
{
203213
$values .= "'".mysql_real_escape_string($pv_val)."',";
204214
}
205-
$sql .= "\n(". rtrim($values, ",") ."),";
215+
$sql .= "\n($values $pv_staticValues),";
206216
}
207217
$sql = rtrim($sql, ",");
208218

modules/import/controller.import.personal.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
});
3535
*/
3636
$ticks->pf_insTick("save");
37-
$saveStatus = $dbPersonal->pf_insRecords($helper->parser->rows[CsvRowState::OK]);
37+
$saveStatus = $dbPersonal->pf_insRecords($helper->parser->rows[CsvRowState::OK], $helper->fileId);
3838
$ticks->pf_endTick("save");
3939
if ($saveStatus) {
4040
if (!empty($_POST['overwrite']) && $_POST['overwrite'] === 'y') {

0 commit comments

Comments
 (0)