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

dev/core#3414 Stop dropping temp table on finish of contact import job #23291

Merged
merged 1 commit into from
Apr 27, 2022

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Apr 23, 2022

Overview

dev/core#3414 Stop dropping temp table on finish of contact import job

Per https://lab.civicrm.org/dev/core/-/issues/3414 the intent is to leave the temp table in place after the job so that the output can be downloaded directly from the temp table. In addition it might be possible to allow viewing without downloading & leaves the potential for updating retrying.

Tracking the temp table through the user job, rather than the forms, also helps towards offline batch processing

Before

The import form process manages the deletion of the import temp tables

After

It is left to the clearTempTables - this clears them after 2 days from the scheduled job or immediately when a more active system flush is done

$dao = new CRM_Core_DAO();
$query = "
SELECT TABLE_NAME as tableName
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = %1
AND (
TABLE_NAME LIKE 'civicrm_import_job_%'
OR TABLE_NAME LIKE 'civicrm_report_temp%'
OR TABLE_NAME LIKE 'civicrm_tmp_d%'
)
";
// NOTE: Cannot find use-cases where "civicrm_report_temp" would be durable. Could probably remove.
if ($timeInterval) {
$query .= " AND CREATE_TIME < DATE_SUB(NOW(), INTERVAL {$timeInterval})";
}

Technical details

If the scheduled job or occassional system flushes are happening (or not much importing is happening) the temp tables won't build up in the database, I might need to look at adding some sort of status check for if they do

The bigger picture is that ideally temp tables will be removed when the row is deleted from civicrm_user_job or when it's expires data passes - this would give more control - eg. to sysadmins who want to check in on imports

This is being done in order to support as-required downloading of output
csv from the temp table.

(note that viewing the temp table directly rather than down loading might
also be on the cards)
@civibot
Copy link

civibot bot commented Apr 23, 2022

(Standard links)

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy this is also fairly simple - but is a pre-requisite for cleaning up some of the datasource code and for switching to downloading csvs based on the import results as in #23292

@Edzelopez
Copy link
Contributor

Hi @eileenmcnaughton

I've tested this (on Monish's direction).

I used the hook_civicrm_import to determine the temp table name used for the import.

Before patch:

Temp table was destroyed as soon as the import was completed.

After patch:

Temp table was retained in the database, with all rows intact. Running cv api System.flush deleted the temp table.

1 similar comment
@Edzelopez
Copy link
Contributor

Hi @eileenmcnaughton

I've tested this (on Monish's direction).

I used the hook_civicrm_import to determine the temp table name used for the import.

Before patch:

Temp table was destroyed as soon as the import was completed.

After patch:

Temp table was retained in the database, with all rows intact. Running cv api System.flush deleted the temp table.

@demeritcowboy demeritcowboy merged commit ecbc16a into civicrm:master Apr 27, 2022
@eileenmcnaughton
Copy link
Contributor Author

thanks @Edzelopez , @demeritcowboy

@eileenmcnaughton eileenmcnaughton deleted the import_output branch April 27, 2022 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants