问题描述:ubuntu下用lua开发游戏电子邮件模块,自己测试时向用户推送100封,而用户最多只能有50封。这是调用sysdelete删除一些邮件。当打印log时,打印到一半后程序中途停止。将打印log的代码删除后又恢复正常。
目前估计是缓存满了。待解决。。删除邮件代码如下:
function _M:sysdelemail()
local readrewarded = {}
local readunrewarded = {}
local unread = {}
for k , v in pairs( self.__data ) do
if 1 == v.isread then
if 1 == v.isreward then
table.insert( readrewarded , v.csv_id )
else
table.insert( readunrewarded , v.csv_id )
end
else
local tmp = {}
tmp.csv_id = v.csv_id
tmp.acctime = v.acctime
table.insert( unread , tmp )
end
end
--delete read and getrewarded first
for _ , v in ipairs( readrewarded ) do
local tmp = self.__data[ tostring( v ) ]
tmp.isdel = 1
tmp:__update_db( { "isdel" } )
self.__data[ tostring( v ) ] = nil
self.__count = self.__count - 1
end
if self.__count <= self.__MAXEMAILNUM then
return
end
-- if still more than MAXEMAILNUMM then delete read , unrewarded
for _ , v in ipairs( readunrewarded ) do
local tmp = self.__data[ tostring( v ) ]
tmp.isdel = 1
tmp:__update_db( { "isdel" } )
self.__data[ tostring( v ) ] = nil
self.__count = self.__count - 1
end
if self.__count <= self.__MAXEMAILNUM then
return
end
-- last delete the earlist unread emails
table.sort( unread , function ( ta , tb ) return ta.acctime < tb.acctime end )
--[[ 如果在此打印排序后的邮件列表变回出现描述的问题打印到一半结束,去掉后却正常
for k , v in ipairs( unread ) do
print( k , v )
end
--]]
local diff = self.__count - self.__MAXEMAILNUM
print( "sizeof diff is ****************************************" , diff , #unread )
local tmp = {}
for i = 1 , diff do
tmp = self.__data[ tostring( unread[ i ].csv_id ) ]
assert( tmp )
tmp.isdel = 1
tmp:__update_db( { "isdel" } )
self.__data[ tostring( unread[ i ].csv_id ) ] = nil
self.__count = self.__count - 1
end
print( "sizeof unread is ****************************************" , self.__count )
end
昨天以为是缓存区满了,但今天又测试的一下,输出更多的log,没有出现昨天的问题。纠结中,现在用的是 skynet 框架 ,仍在学习中。感觉这会是个定时炸弹,不知哪天爆了。希望用skynet并pengdao过类似问题的同学不吝赐教。。