Fix cacheing
Fix some cache invalidation bugs that would cause the index and author pages to not update correctly when new pastes were made.
This commit is contained in:
parent
910542ef76
commit
2e735282ec
|
@ -1,7 +1,9 @@
|
|||
local et = require("etlua")
|
||||
local sql = require("lsqlite3")
|
||||
local zlib = require("zlib")
|
||||
if PRODUCTION then
|
||||
local function print() end --squash prints
|
||||
end
|
||||
local parser_names = {"plain","imageboard"}
|
||||
local parsers = {}
|
||||
for _,v in pairs(parser_names) do
|
||||
|
@ -231,7 +233,7 @@ end
|
|||
|
||||
local function dirty_cache(url)
|
||||
stmnt_dirty_cache:bind_names{
|
||||
path = string.format("%s/%s",domain,url)
|
||||
path = url
|
||||
}
|
||||
err = do_sql(stmnt_dirty_cache)
|
||||
stmnt_dirty_cache:reset()
|
||||
|
@ -330,7 +332,7 @@ function home(req)
|
|||
local text
|
||||
if host == domain then
|
||||
--Default home page
|
||||
text = render(host..path,function()
|
||||
text = render(string.format("%s",domain),function()
|
||||
print("Cache miss, rendering index")
|
||||
stmnt_index:bind_names{}
|
||||
local err = do_sql(stmnt_index)
|
||||
|
@ -417,7 +419,7 @@ function claim(req)
|
|||
local text
|
||||
if method == "GET" then
|
||||
--Get the page to claim a name
|
||||
text = render(host..path,function()
|
||||
text = render(string.format("%s/_claim",domain),function()
|
||||
print("cache miss, rendering claim page")
|
||||
return pages.claim{}
|
||||
end)
|
||||
|
@ -474,10 +476,11 @@ function paste(req)
|
|||
--Get the paste page
|
||||
if host == domain then
|
||||
--For an anonymous user
|
||||
ret = render(host..path,function()
|
||||
ret = render(string.format("%s/_paste",host),function()
|
||||
print("Cache missing, rendering post page")
|
||||
return pages.paste{
|
||||
domain = domain,
|
||||
err = "",
|
||||
}
|
||||
end)
|
||||
else
|
||||
|
@ -508,6 +511,7 @@ function paste(req)
|
|||
domain = domain,
|
||||
user = author,
|
||||
text = "",
|
||||
err = "",
|
||||
}
|
||||
end
|
||||
elseif method == "POST" then
|
||||
|
@ -615,6 +619,7 @@ function paste(req)
|
|||
http_response(req,303,"")
|
||||
stmnt_paste:reset()
|
||||
stmnt_raw:reset()
|
||||
dirty_cache(string.format("%s.%s",author,domain))
|
||||
dirty_cache(string.format("%s/%s",domain,url))
|
||||
dirty_cache(string.format("%s",domain))
|
||||
return
|
||||
|
@ -632,7 +637,7 @@ end
|
|||
|
||||
--A helper function for below
|
||||
local function read_story(host,path,idp)
|
||||
return render(host..path,function()
|
||||
return render(string.format("%s%s",host,path),function()
|
||||
print("Trying to read, id is",idp,":",decode_id(idp))
|
||||
local id = decode_id(idp)
|
||||
print("id:",id,type(id))
|
||||
|
@ -679,15 +684,16 @@ function read(req)
|
|||
if err == sql.DONE then
|
||||
--We got no story
|
||||
stmnt_read:reset()
|
||||
return pages.nostory{
|
||||
text = pages.nostory{
|
||||
path = path
|
||||
}
|
||||
end
|
||||
else
|
||||
assert(err == sql.ROW)
|
||||
local title, storytext, tauthor, isanon, authorname = unpack(stmnt_read:get_values())
|
||||
storytext = zlib.decompress(storytext)
|
||||
stmnt_read:reset()
|
||||
if tauthor == authorid then
|
||||
print("we're the author!")
|
||||
--The story exists and we're logged in as the
|
||||
--owner, display the edit button
|
||||
text = pages.read{
|
||||
|
@ -701,8 +707,10 @@ function read(req)
|
|||
}
|
||||
|
||||
else
|
||||
print("we're not the author!")
|
||||
text = read_story(host,path,idp)
|
||||
end
|
||||
end
|
||||
else
|
||||
text = read_story(host,path,idp)
|
||||
end
|
||||
|
@ -723,7 +731,7 @@ function login(req)
|
|||
local text
|
||||
if method == "GET" then
|
||||
--Just give them the login page
|
||||
text = render(host..path,function()
|
||||
text = render(string.format("%s/_login",domain),function()
|
||||
return pages.login{
|
||||
err = "",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue