Skip to content

Commit

Permalink
added a lua copy of data files to massively speed up load times
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejsavage committed Jul 4, 2011
1 parent a60e3e9 commit e3741a7
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 8 deletions.
1 change: 1 addition & 0 deletions data/armors.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/charms.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/charmsFiltered.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/decorations.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/guns.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/items.lua

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/modified.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {["js/items.js"]=1300815788,["js/ajax.js"]=1297109297,["data/js/charms.js"]=1300816738,["data/js/armors.js"]=1301425692,["js/generator.js"]=1297112177,["data/js/items.js"]=1301744721,["js/common.js"]=1300143850,["data/js/skills.js"]=1299877781,["css/common.css"]=1301745398,["js/defer.js"]=1300144317,["data/js/decorations.js"]=1301333391,["js/bench.js"]=1298466233,["js/builder.js"]=1301593030,["js/weaponTree.js"]=1301080549,}
1 change: 1 addition & 0 deletions data/monsters.lua

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions data/posts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
return {{["date"]=1300996194,["content"]="<h3>SEO 101</h3>I've bought the domain <a href=\"http://p3db.com/\">p3db.com</a>\
and changed the name of the site to P3DB to match. I've been eyeing it for a while, but it seems it takes\
a domain <s>30 days</s> <s>35 days</s> goddamn forever to expire. divinewh.im is a bit awkward to type and gets\
absolutely <em>horrible</em> search ranking. Some stats:\
<ul>\
<li>Visits to TriDB this month: <b>over 70,000</b></li>\
<li>Referrals from Google this month: <b>1,105</b></li>\
</ul>\
Yes, that is less than 2%. No, really. And it gets better:\
<ul>\
<li>The click through rate when searching for divinewh.im (the site's URL!) is <b>18%</b></li>\
</ul>\
Have I set a world record?\
<br><br>\
There's also been a little general progress - monster icons are all\
there now (although they definitely need a little improvement) and the\
HH tree has received some attention. Expect more to be added this\
weekend.\
<br><br>\
- Mike",},{["date"]=1300642552,["content"]="Over the last week or so I've added 150+ weapons, which has brought the\
weapon trees to over 50% completion. It should be quite obvious which\
weapons I like in this game. There still a few sharpness bars missing/without Sharpness +1 here and there and none of the trees are actually complete\
yet - LS is the closest with six remaining.\
\
<br><br>\
\
Since I dropped some figures, I guess I should do a proper progress\
report for those who are interested:\
\
<ul>\
<li>The weapon trees are <b>55.9%</b> done</li>\
<li>The armor lists are <b>87.6%</b> done - I think there's just\
Atea S and event equipment left to add</li>\
<li>The decorations list is <b>98.2%</b> done with just three\
remaining</li>\
<li>The sissy weapon trees are <b>49.8%</b> complete, which is\
surprising since I've added maybe five upgrades</li>\
</ul>\
\
<br>\
\
I added the monsters section this afternoon but it's currently in quite a\
sad state, both site wise and code wise. It should begin to look better\
as I add the remaining monster icons (most of them...) and things like\
break rewards. Hitzone info is also a high priority since the damage\
calculator depends on it, and who didn't love that?\
\
<br><br>\
\
- Mike",},{["date"]=1299939185,["content"]="An obvious change I've made is adding this section instead of the commits\
list. It got replaced because I tend to make lots of commits over a few\
days before uploading the changes to this site (due to incompleteness etc)\
so more often than not a bunch of them would get cut off. My commit\
messages sometimes <a href=\"https://github.com/mikejsavage/MHP3DB/commit/3d20fc41a3f2196fbfa1148408c800ffa46f192c\">aren't</a> <a href=\"https://github.com/mikejsavage/MHP3DB/commit/37730fa5b30b8cbc371b128d08c03b501b590b44\">very</a> <a href=\"https://github.com/mikejsavage/MHP3DB/commit/22192dafa6a736a7bd99396e0a6b4348d6a6a681\">helpful</a> either.\
<br><br>\
Another change is the addition of protips at the top of the page. As with <a href=\"http://divinewh.im/\">TriDB</a>, there will be a mix of tongue in cheek and serious tips, and hopefully nothing that's blindingly obvious. If you have any, please send\
them in! You'll have to use the <a href=\"http://divinewh.im/f/\">TriDB\
feedback form</a> for now, as creating a separate one for here isn't\
high on my list of things to do.\
<br><br>\
If anyone knows how to extract things like quest data and monster carve\
info from the game, I'd very much appreciate it if you could tell me how\
using the form I linked to above.\
<br><br>\
- Mike",},}
1 change: 1 addition & 0 deletions data/shots.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {{["name"]={["hgg"]="Normal",},["levels"]=3,},{["name"]={["hgg"]="Pierce",},["levels"]=3,},{["name"]={["hgg"]="Pellet",},["levels"]=3,},{["name"]={["hgg"]="Crag",},["levels"]=3,},{["name"]={["hgg"]="Clust",},["levels"]=3,},{["name"]={["hgg"]="Recov",},["levels"]=2,},{["name"]={["hgg"]="Poisn",},["levels"]=2,},{["name"]={["hgg"]="Para",},["levels"]=2,},{["name"]={["hgg"]="Sleep",},["levels"]=2,},{["name"]={["hgg"]="Fatigue",},["levels"]=2,},{["name"]={["hgg"]="Flame",},["levels"]=1,},{["name"]={["hgg"]="Water",},["levels"]=1,},{["name"]={["hgg"]="Thundr",},["levels"]=1,},{["name"]={["hgg"]="Freeze",},["levels"]=1,},{["name"]={["hgg"]="Dragon",},["levels"]=1,},{["name"]={["hgg"]="Tranq",},["levels"]=1,},{["name"]={["hgg"]="Paint",},["levels"]=1,},{["name"]={["hgg"]="Demon",},["levels"]=1,},{["name"]={["hgg"]="Armor",},["levels"]=1,},{["name"]={["hgg"]="Cutter",},["levels"]=1,},}
1 change: 1 addition & 0 deletions data/skills.lua

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions data/temp/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,69 @@ function colorEqual( c1, c2 )
c1.green == c2.green and
c1.blue == c2.blue
end

local function isArray( table )
-- arrays have to be sequential
local expectedIdx = 1

for key, _ in pairs( table ) do
if type( key ) ~= "number" or key ~= expectedIdx then
return false
end

expectedIdx = expectedIdx + 1
end

return true
end

local function serializeObjectToFile( file, obj )
local t = type( obj )

if t == "number" or t == "boolean" then
file:write( tostring( obj ) )

return
end

if t == "string" then
file:write( ( "%q" ):format( obj ) )

return
end

if t == "table" then
file:write( "{" )

if isArray( obj ) then
for _, v in ipairs( obj ) do
serializeObjectToFile( file, v )

file:write( "," )
end
else
for k, v in pairs( obj ) do
file:write( "[" )
file:write( ( "%q" ):format( k ) )
file:write( "]" )
file:write( "=" )

serializeObjectToFile( file, v )

file:write( "," )
end
end

file:write( "}" )

return
end

error( "I don't know how to serialize type " .. t )
end

function serializeToFile( file, obj )
file:write( "return " )

serializeObjectToFile( file, obj )
end
32 changes: 32 additions & 0 deletions data/temp/genLuaData.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/lua

require( "common" )

local Files =
{
"armors",
"charms",
"charmsFiltered",
"decorations",
"guns",
"items",
"modified",
"monsters",
"posts",
"shots",
"skills",
"tips",
"weapons",
}

for _, file in ipairs( Files ) do
local arr = data( file )

local output = assert( io.open( "../" .. file .. ".lua", "w" ) )

serializeToFile( output, arr )

output:close()
end

print( "genLuaData: done!" )
1 change: 1 addition & 0 deletions data/tips.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {"Spare a thought <a href='http://www1.networkforgood.org/help-survivors-pacific-quake-tsunami'>and consider donating</a> for those affected by the disaster in Japan.",}
1 change: 1 addition & 0 deletions data/weapons.lua

Large diffs are not rendered by default.

Binary file modified fcgi
Binary file not shown.
11 changes: 9 additions & 2 deletions fcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,22 @@ int main( int argc, char *argv[] )
// SIGUSR1 is sent when the server is shutting down
signal( SIGUSR1, cleanup );

// register functions
lua_register( L, "print", fcgiPrint );

( void ) luaL_dofile( L, "fcgi.lua" );

// put debug.traceback on the stack
lua_getglobal( L, "debug" );
lua_getfield( L, -1, "traceback" );
lua_remove( L, -2 );

// load init script
if( luaL_loadfile( L, "fcgi.lua" ) || lua_pcall( L, 0, 0, -2 ) )
{
printf( "Error loading fcgi.lua: %s\n", lua_tostring( L, -1 ) );

exit( 1 );
}

while( FCGI_Accept() >= 0 )
{
// POST parsing
Expand Down
10 changes: 5 additions & 5 deletions inc/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--
-- so i guess this is BSD licensed? i'm not very good at this

TemplateCache = { }
--TemplateCache = { }

local Actions =
{
Expand Down Expand Up @@ -75,15 +75,15 @@ function compileTemplate( template, name )
end

function loadTemplate( file )
if TemplateCache[ file ] then
--[[if TemplateCache[ file ] then
return TemplateCache[ file ]
end
end]]

local template = compileTemplate( readFile( ( "%s/%s.lua" ):format( TemplatesDir, file ) ), file )

if not IsLocalHost then
--[[if not IsLocalHost then
TemplateCache[ file ] = template
end
end]]

return template
end
Expand Down
2 changes: 1 addition & 1 deletion inc/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
function data( file )
local contents = readFile( ( "data/%s.json" ):format( file ) )

return json.decode( contents ), contents
return dofile( ( "data/%s.lua" ):format( file ) ), contents
end

-- returns true if self starts with needle
Expand Down

0 comments on commit e3741a7

Please sign in to comment.