humanmade / WordPress-Importer

In-development rewrite of the WordPress (WXR) Importer
Other
358 stars 63 forks source link

Redundant, maybe unnecessary, term caching. #130

Open dcavins opened 7 years ago

dcavins commented 7 years ago

Hi all-

in WXR_Importer, there are two arrays that are used to cache terms: (The $mapping_key is calculated as sha1( taxonomy:slug ) in every case below.) $this->mapping['term'][ $mapping_key ] = $term_id entries are created as terms are created.

$this->exists['term'][ $mapping_key ] = $term_id entries are populated at the start with all existing terms if prefill_existing_terms is true. Entries also need to be added as new terms are created.

There's also an array that maps the old term ID to the new term ID. $this->mapping['term_id'][ $original_id ] = $term_id

In looking at WP export files it seems that all terms are referred to by their taxonomy and slug: Example term description: <wp:term><wp:term_id>1420</wp:term_id><wp:term_taxonomy>geographies</wp:term_taxonomy><wp:term_slug>alaska-state</wp:term_slug><wp:term_parent>united-states</wp:term_parent><wp:term_name><![CDATA[Alaska]]></wp:term_name><wp:term_description><![CDATA[04000US02]]></wp:term_description></wp:term> Note that the parent term is given as a slug, too.

Terms are referenced in post output as slugs: <category domain="goals" nicename="healthy-child"><![CDATA[Healthy Child]]></category>

Since the taxonomy/slug pair is used as a unique key, I'm wondering if we could get away with using the $exists array only for terms. I'm not able to think of any examples where the old ID would need to be mapped to the new ID, and the slug wouldn't get the job done.

I'd be happy to submit a PR simplifying the term code if you agree.

Thanks again for all the work on this new plugin.

-David