[libpeas] engine: sort unresolved plugins at tail of queue



commit 3e335c9e9257c05a000a891422f5cc28c1f77d4b
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 18 14:09:26 2022 -0700

    engine: sort unresolved plugins at tail of queue
    
    If we have a plugin we've added that we could not resolve all the
    dependencies for then push it to the tail of the queue. That way, further
    insertions of plugins are more likely to sort before the plugin.
    
    Otherwise, we can push the info to the head as it has no dependencies.
    
    This improves a situation in Builder where plugins that dependend on
    plugins which also had dependencies could end up loading in the wrong
    order.

 libpeas/peas-engine.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index b6eee05..c0ccae8 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -144,12 +144,22 @@ plugin_info_add_sorted (GQueue         *plugin_list,
         }
     }
 
-  /* GLib changed only accepts NULL for
-   * g_queue_insert_after() at version 2.44
-   */
   if (furthest_dep == NULL)
     {
-      g_queue_push_head (plugin_list, info);
+      /* If we have dependencies and we didn't find any matches yet,
+       * then push the item to the tail to improve the chances that
+       * the dependencies will resolve in the proper order. Otherwise
+       * a plugin that has dependency (which also has a dependency)
+       * can resolve in the wrong order.
+       *
+       * Another option here is to do proper dependency solving but
+       * the way things are designed to do resolving at each info
+       * load means that we'd do the depsolve more than necessary.
+       */
+      if (dependencies[0] != NULL)
+        g_queue_push_tail (plugin_list, info);
+      else
+        g_queue_push_head (plugin_list, info);
       return;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]