Opened 2 years ago

Closed 13 months ago

#208 closed defect (fixed)

String counts caching issues

Reported by: dimadin Owned by: markoheijnen
Milestone: 1.0 Priority: normal
Version: Component: Cache
Keywords: has-patch Cc: juanramon.diaz@…


After numerous reports on WP Polyglots, I've looked into the GlotPress code to see what and where we're caching and when that cache is cleared.

There are two caches that we have and that affect us: active_originals_count_by_project_id which is a number of active strings in a project, and translation_set_status_breakdown, which is per translation set cache that contains counts of each status of string except of untranslated strings.

First cache is cleared when originals are imported into the project and that is fine. Second cache is cleared when new translation is added but there are actions that don't clear cache and I believe this is what is causing problems.

Translation set's cache isn't cleared when single string translation status is changed, when originals are imported, and when translation set is copied from another. Second case is responsible for weird numbers like negative number of untranslated strings. (this probably happens when approved strings become obsolete during import of originals: in that process count of total strings is refreshed while count of untranslated strings is dynamically generated as difference between total strings (from clean cache) and count of translated strings (from old cache), and if there is larger number of translated strings in old cache than new number of total strings, we get negative number)

So I suggest that we clear translation set's cache in functions I linked above.


Attachments (1)

gp_cache_fix.patch (6.6 KB) - added by dimadin 2 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 dimadin2 years ago

  • Keywords has-patch added

I created a patch. It doesn't just include cache cleaning on missing places, but it also moves all cleaning to hooks. Why? Because that way other tools can benefit too. For example, on wp.org we can have a plugin that will clean language packages when changes are made. Or there can be notification plugin when actions are made etc.

Not tested with object cache enabled.

dimadin2 years ago

comment:2 defries21 months ago

  • Milestone set to 1.0

comment:3 markoheijnen15 months ago

  • Component changed from performance to Cache

Will be looking into this after WordSesh.

comment:4 markoheijnen15 months ago

  • Owner set to markoheijnen
  • Status changed from new to accepted

comment:5 markoheijnen13 months ago

In 777:

First pass on fixing the translations set count cache. Also fixes setting strings obsolete when they already are obsolete

props dimadin. See #208

comment:6 markoheijnen13 months ago

Just did a first pass on fixing this. Didn't used the hooks for clearing the cache since you shouldn't be able to unhook them. So this commit mainly fix clearing the cache when new strings are imported.

Fix minor issue with strings getting set as obsolete when they already are obsolete. Needed to fix that for the counter otherwise the cache would always be cleared when there is already one obsolete string.

Delete cache inside copy_translations_from() shouldn't be needed so didn't add that one. Maybe we should request non cache data there. Not sure yet about the one inside edit_single_translation().

comment:7 markoheijnen13 months ago

In 785:

Renamed cache functions names to be more like WordPress naming conventions. See #208

comment:8 juanramondiaz13 months ago

  • Cc juanramon.diaz@… added

comment:9 markoheijnen13 months ago

In 788:

Added two actions: originals_imported and translations_imported. See #208

comment:10 markoheijnen13 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

Closing the ticket as fixed. If something is missing or wrong please reopen it.

Note: See TracTickets for help on using tickets.