@@ -25,11 +25,17 @@ defmodule Kaffy.ResourceQuery do
25
25
current_offset
26
26
)
27
27
28
- custom_query = Kaffy.ResourceAdmin . custom_index_query ( conn , resource , paged )
29
- current_page = Kaffy.Utils . repo ( ) . all ( custom_query )
28
+ { current_page , opts } =
29
+ case Kaffy.ResourceAdmin . custom_index_query ( conn , resource , paged ) do
30
+ { custom_query , opts } ->
31
+ { Kaffy.Utils . repo ( ) . all ( custom_query , opts ) , opts }
32
+
33
+ custom_query ->
34
+ { Kaffy.Utils . repo ( ) . all ( custom_query ) , [ ] }
35
+ end
30
36
31
37
do_cache = if search == "" and Enum . empty? ( filtered_fields ) , do: true , else: false
32
- all_count = cached_total_count ( schema , do_cache , all )
38
+ all_count = cached_total_count ( schema , do_cache , all , opts )
33
39
{ all_count , current_page }
34
40
end
35
41
@@ -47,8 +53,11 @@ defmodule Kaffy.ResourceQuery do
47
53
def fetch_resource ( conn , resource , id ) do
48
54
schema = resource [ :schema ]
49
55
query = from ( s in schema , where: s . id == ^ id )
50
- custom_query = Kaffy.ResourceAdmin . custom_show_query ( conn , resource , query )
51
- Kaffy.Utils . repo ( ) . one ( custom_query )
56
+
57
+ case Kaffy.ResourceAdmin . custom_show_query ( conn , resource , query ) do
58
+ { custom_query , opts } -> Kaffy.Utils . repo ( ) . one ( custom_query , opts )
59
+ custom_query -> Kaffy.Utils . repo ( ) . one ( custom_query )
60
+ end
52
61
end
53
62
54
63
def fetch_list ( _ , [ "" ] ) , do: [ ]
@@ -60,10 +69,12 @@ defmodule Kaffy.ResourceQuery do
60
69
|> Kaffy.Utils . repo ( ) . all ( )
61
70
end
62
71
63
- def total_count ( schema , do_cache , query ) do
72
+ def total_count ( schema , do_cache , query , opts \\ [ ] )
73
+
74
+ def total_count ( schema , do_cache , query , opts ) do
64
75
result =
65
76
from ( s in query , select: fragment ( "count(*)" ) )
66
- |> Kaffy.Utils . repo ( ) . one ( )
77
+ |> Kaffy.Utils . repo ( ) . one ( opts )
67
78
68
79
if do_cache and result > 100_000 do
69
80
Kaffy.Cache.Client . add_cache ( schema , "count" , result , 600 )
@@ -72,10 +83,12 @@ defmodule Kaffy.ResourceQuery do
72
83
result
73
84
end
74
85
75
- def cached_total_count ( schema , false , query ) , do: total_count ( schema , false , query )
86
+ def cached_total_count ( schema , do_cache , query , opts \\ [ ] )
87
+
88
+ def cached_total_count ( schema , false , query , opts ) , do: total_count ( schema , false , query , opts )
76
89
77
- def cached_total_count ( schema , do_cache , query ) do
78
- Kaffy.Cache.Client . get_cache ( schema , "count" ) || total_count ( schema , do_cache , query )
90
+ def cached_total_count ( schema , do_cache , query , opts ) do
91
+ Kaffy.Cache.Client . get_cache ( schema , "count" ) || total_count ( schema , do_cache , query , opts )
79
92
end
80
93
81
94
defp get_filter_fields ( params , resource ) do
0 commit comments