[Groonga-commit] groonga/groonga at d50a8a3 [master] snippet_html: improve performance by caching grn_cache

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Sep 9 00:08:10 JST 2015


Kouhei Sutou	2015-09-09 00:08:10 +0900 (Wed, 09 Sep 2015)

  New Revision: d50a8a3228935a7d671dde051a0834d0ad5bdeec
  https://github.com/groonga/groonga/commit/d50a8a3228935a7d671dde051a0834d0ad5bdeec

  Message:
    snippet_html: improve performance by caching grn_cache

  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+25 -9)
===================================================================
--- lib/proc.c    2015-09-09 21:21:32 +0900 (76bb34e)
+++ lib/proc.c    2015-09-09 00:08:10 +0900 (b6d8eb6)
@@ -61,6 +61,7 @@ const char *grn_document_root = NULL;
 
 #define GRN_SELECT_INTERNAL_VAR_CONDITION     "$condition"
 #define GRN_SELECT_INTERNAL_VAR_MATCH_COLUMNS "$match_columns"
+#define GRN_FUNC_SNIPPET_HTML_CACHE_NAME      "$snippet_html"
 #define GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME    "$highlight_html"
 
 
@@ -5022,20 +5023,35 @@ func_snippet_html(grn_ctx *ctx, int nargs, grn_obj **args,
     }
 
     if (condition) {
-      snip = grn_snip_open(ctx, flags, width, max_n_results,
-                           open_tag, strlen(open_tag),
-                           close_tag, strlen(close_tag),
-                           mapping);
-      if (snip) {
-        grn_snip_set_normalizer(ctx, snip, GRN_NORMALIZER_AUTO);
-        grn_expr_snip_add_conditions(ctx, condition, snip,
-                                     0, NULL, NULL, NULL, NULL);
+      grn_obj *snip_ptr;
+      snip_ptr = grn_expr_get_var(ctx, expression,
+                                  GRN_FUNC_SNIPPET_HTML_CACHE_NAME,
+                                  strlen(GRN_FUNC_SNIPPET_HTML_CACHE_NAME));
+      if (snip_ptr) {
+        snip = GRN_PTR_VALUE(snip_ptr);
+      } else {
+        snip_ptr =
+          grn_expr_get_or_add_var(ctx, expression,
+                                  GRN_FUNC_SNIPPET_HTML_CACHE_NAME,
+                                  strlen(GRN_FUNC_SNIPPET_HTML_CACHE_NAME));
+        GRN_OBJ_FIN(ctx, snip_ptr);
+        GRN_PTR_INIT(snip_ptr, GRN_OBJ_OWN, GRN_DB_OBJECT);
+
+        snip = grn_snip_open(ctx, flags, width, max_n_results,
+                             open_tag, strlen(open_tag),
+                             close_tag, strlen(close_tag),
+                             mapping);
+        if (snip) {
+          grn_snip_set_normalizer(ctx, snip, GRN_NORMALIZER_AUTO);
+          grn_expr_snip_add_conditions(ctx, condition, snip,
+                                       0, NULL, NULL, NULL, NULL);
+          GRN_PTR_SET(ctx, snip_ptr, snip);
+        }
       }
     }
 
     if (snip) {
       snippets = snippet_exec(ctx, snip, text, user_data);
-      grn_obj_close(ctx, snip);
     }
   }
 
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index