Android: `EditorService` does disk and SSL work on the caller's thread

Abierto
#869 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
android, kotlin

Línea de trabajo

Start with EditorService (create, prepare, fetchAssetBundleCount, cleanup, purge) and EditorDependenciesSerializer (writeToDisk, readFromDisk), then trace the disk and SSL calls into EditorAssetsLibrary.readAssetBundles and the EditorHTTPClient setup. Begin with the first proposed step: move the cleanup() call inside prepare onto Dispatchers.IO. Done means prepare is safe on the main thread, and every other listed API either runs off the caller's thread or documents that it blocks. The API shape is still undecided, so confirm the approach with maintainers before changing signatures.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

[Type] Code Quality Android

EditorService and EditorDependenciesSerializer do disk and SSL work on whichever thread calls them, so a host that calls them on the main thread gets slow frames and StrictMode violations. Nothing in the API or its KDoc says to avoid this.

No shipping host is affected today. WordPress-Android calls EditorService.create and prepare from a background dispatcher in GutenbergEditorPreloader. It also doesn't use the serializer or the other calls below, and its StrictMode setup is commented out. The cost is to the next host, and to the demo app, which wraps every call by hand (#489).

This is separate from #848, which covers the work inside GutenbergView that a host can't move. These are calls the host makes itself, so they can move.

What happens

API Blocking work Why it matters
EditorService.create EditorHTTPClient SSL setup, Paths.*Root, getSharedPreferences, EditorURLCache and EditorAssetsLibrary init Not suspend, so nothing suggests it blocks
EditorService.prepare Periodic cleanup() → EditorAssetsLibrary.readAssetBundles It's suspend, so callers will expect it to be safe on the main thread
EditorService.fetchAssetBundleCount EditorAssetsLibrary.readAssetBundles Not suspend
EditorService.cleanup, purge Deletes files Not suspend
EditorDependenciesSerializer.writeToDisk, readFromDisk Reads or writes the dependencies file Not suspend

Possible fix

  1. prepare: run cleanup() on Dispatchers.IO inside the library. This has no API change and should come first.
  2. The rest: make them suspend and move to Dispatchers.IO inside the library. This is a breaking change for hosts, though a small one, since WordPress-Android already calls create from a coroutine.
  3. If 2 is too disruptive: document the blocking calls in KDoc instead.

Done when

  • prepare is safe to call from the main thread.
  • Each API above either moves its work off the caller's thread or says in its KDoc that it blocks.
  • The demo's withContext(Dispatchers.IO) wrappers around these calls are removed where they're no longer needed.

Related issues

  • #848 — editor load work inside GutenbergView.
  • #489 — the demo app wrappers, and the review that raised this.
Lenguaje dominante
JavaScript
Estrellas
29
Forks
6
Merge medio
2 d 1 h
PR fusionados (30 d)
76

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wordpress-mobile/GutenbergKit

Todos los issues de wordpress-mobile/GutenbergKit

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.