Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
0x4A6F
FFS Gluon
Commits
eba7ecbb
Commit
eba7ecbb
authored
9 years ago
by
Matthias Schiffer
Browse files
Options
Downloads
Patches
Plain Diff
gluon-announced: add support for caching announced data
parent
5927fd66
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package/gluon-announced/files/usr/lib/lua/gluon/announced.lua
+27
-6
27 additions, 6 deletions
...age/gluon-announced/files/usr/lib/lua/gluon/announced.lua
with
27 additions
and
6 deletions
package/gluon-announced/files/usr/lib/lua/gluon/announced.lua
+
27
−
6
View file @
eba7ecbb
local
announce
=
require
'gluon.announce'
local
deflate
=
require
'deflate'
local
json
=
require
'luci.jsonc'
local
util
=
require
'luci.util'
local
nixio
=
require
'nixio'
local
fs
=
require
'nixio.fs'
...
...
@@ -10,16 +11,36 @@ nixio.chdir('/lib/gluon/announce/')
for
dir
in
fs
.
glob
(
'*.d'
)
do
local
name
=
dir
:
sub
(
1
,
-
3
)
memoize
[
name
]
=
announce
.
collect_dir
(
dir
)
memoize
[
name
]
=
{
collect
=
announce
.
collect_dir
(
dir
),
-- tonumber will return 0 for invalid inputs
cache_time
=
tonumber
(
util
.
trim
(
fs
.
readfile
(
name
..
'.cache'
)
or
''
))
}
end
local
function
collect
(
type
)
return
memoize
[
type
]
and
memoize
[
type
]()
local
function
collect
(
type
,
timestamp
)
local
c
=
memoize
[
type
]
if
not
c
then
return
nil
end
if
c
.
cache_timeout
and
timestamp
<
c
.
cache_timeout
then
return
c
.
cache
else
local
ret
=
c
.
collect
()
if
c
.
cache_time
then
c
.
cache
=
ret
c
.
cache_timeout
=
timestamp
+
c
.
cache_time
end
return
ret
end
end
module
(
'gluon.announced'
,
package
.
seeall
)
function
handle_request
(
query
)
function
handle_request
(
query
,
timestamp
)
collectgarbage
()
local
m
=
query
:
match
(
'^GET ([a-z ]+)$'
)
...
...
@@ -28,7 +49,7 @@ function handle_request(query)
local
data
=
{}
for
q
in
m
:
gmatch
(
'([a-z]+)'
)
do
local
ok
,
val
=
pcall
(
collect
,
q
)
local
ok
,
val
=
pcall
(
collect
,
q
,
timestamp
)
if
ok
then
data
[
q
]
=
val
end
...
...
@@ -38,7 +59,7 @@ function handle_request(query)
ret
=
deflate
.
compress
(
json
.
stringify
(
data
))
end
elseif
query
:
match
(
'^[a-z]+$'
)
then
local
ok
,
data
=
pcall
(
collect
,
query
)
local
ok
,
data
=
pcall
(
collect
,
query
,
timestamp
)
if
ok
then
ret
=
json
.
stringify
(
data
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment