Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
ffbs-gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ffbs
ffbs-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
announce
=
require
'gluon.announce'
local
deflate
=
require
'deflate'
local
deflate
=
require
'deflate'
local
json
=
require
'luci.jsonc'
local
json
=
require
'luci.jsonc'
local
util
=
require
'luci.util'
local
nixio
=
require
'nixio'
local
nixio
=
require
'nixio'
local
fs
=
require
'nixio.fs'
local
fs
=
require
'nixio.fs'
...
@@ -10,16 +11,36 @@ nixio.chdir('/lib/gluon/announce/')
...
@@ -10,16 +11,36 @@ nixio.chdir('/lib/gluon/announce/')
for
dir
in
fs
.
glob
(
'*.d'
)
do
for
dir
in
fs
.
glob
(
'*.d'
)
do
local
name
=
dir
:
sub
(
1
,
-
3
)
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
end
local
function
collect
(
type
)
local
function
collect
(
type
,
timestamp
)
return
memoize
[
type
]
and
memoize
[
type
]()
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
end
module
(
'gluon.announced'
,
package
.
seeall
)
module
(
'gluon.announced'
,
package
.
seeall
)
function
handle_request
(
query
)
function
handle_request
(
query
,
timestamp
)
collectgarbage
()
collectgarbage
()
local
m
=
query
:
match
(
'^GET ([a-z ]+)$'
)
local
m
=
query
:
match
(
'^GET ([a-z ]+)$'
)
...
@@ -28,7 +49,7 @@ function handle_request(query)
...
@@ -28,7 +49,7 @@ function handle_request(query)
local
data
=
{}
local
data
=
{}
for
q
in
m
:
gmatch
(
'([a-z]+)'
)
do
for
q
in
m
:
gmatch
(
'([a-z]+)'
)
do
local
ok
,
val
=
pcall
(
collect
,
q
)
local
ok
,
val
=
pcall
(
collect
,
q
,
timestamp
)
if
ok
then
if
ok
then
data
[
q
]
=
val
data
[
q
]
=
val
end
end
...
@@ -38,7 +59,7 @@ function handle_request(query)
...
@@ -38,7 +59,7 @@ function handle_request(query)
ret
=
deflate
.
compress
(
json
.
stringify
(
data
))
ret
=
deflate
.
compress
(
json
.
stringify
(
data
))
end
end
elseif
query
:
match
(
'^[a-z]+$'
)
then
elseif
query
:
match
(
'^[a-z]+$'
)
then
local
ok
,
data
=
pcall
(
collect
,
query
)
local
ok
,
data
=
pcall
(
collect
,
query
,
timestamp
)
if
ok
then
if
ok
then
ret
=
json
.
stringify
(
data
)
ret
=
json
.
stringify
(
data
)
end
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