mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
pipline方法优化 (#1771)
1、增加sort_statge、skip_statge、limit_statge、count_statge替换临时table 2、改成for i = 1, 2 do self.__pipeline[len + i] = nil end清除老数据
This commit is contained in:
@@ -768,29 +768,34 @@ function mongo_cursor:close()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local sort_stage = { ["$sort"] = true }
|
||||||
|
local skip_stage = { ["$skip"] = 0 }
|
||||||
|
local limit_stage = { ["$limit"] = 0 }
|
||||||
|
local count_stage = { ["$count"] = "__count" }
|
||||||
local function format_pipeline(self, with_limit_and_skip, is_count)
|
local function format_pipeline(self, with_limit_and_skip, is_count)
|
||||||
local len = self.__pipeline_len
|
local len = self.__pipeline_len
|
||||||
if self.__sort and not is_count then
|
if self.__sort and not is_count then
|
||||||
len = len + 1
|
len = len + 1
|
||||||
self.__pipeline[len] = { ["$sort"] = self.__sort }
|
sort_stage["$sort"] = self.__sort
|
||||||
|
self.__pipeline[len] = sort_stage
|
||||||
end
|
end
|
||||||
if with_limit_and_skip then
|
if with_limit_and_skip then
|
||||||
if self.__skip > 0 then
|
if self.__skip > 0 then
|
||||||
len = len + 1
|
len = len + 1
|
||||||
self.__pipeline[len] = { ["$skip"] = self.__skip }
|
skip_stage["$skip"] = self.__skip
|
||||||
|
self.__pipeline[len] = skip_stage
|
||||||
end
|
end
|
||||||
if self.__limit > 0 then
|
if self.__limit > 0 then
|
||||||
len = len + 1
|
len = len + 1
|
||||||
self.__pipeline[len] = { ["$limit"] = self.__limit }
|
limit_stage["$limit"] = self.__limit
|
||||||
|
self.__pipeline[len] = limit_stage
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if is_count then
|
if is_count then
|
||||||
len = len + 1
|
len = len + 1
|
||||||
self.__pipeline[len] = { ["$count"] = "__count" }
|
self.__pipeline[len] = count_stage
|
||||||
end
|
|
||||||
for i = #self.__pipeline, len + 1, -1 do
|
|
||||||
table.remove(self.__pipeline, i)
|
|
||||||
end
|
end
|
||||||
|
for i = 1, 2 do self.__pipeline[len + i] = nil end
|
||||||
return self.__pipeline
|
return self.__pipeline
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user