Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
srvpro
Commits
a166c390
Commit
a166c390
authored
Oct 03, 2018
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make cache customizable
parent
e0734dc5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
14 deletions
+24
-14
data/default_config.json
data/default_config.json
+1
-0
ygopro-server.coffee
ygopro-server.coffee
+10
-7
ygopro-server.js
ygopro-server.js
+13
-7
No files found.
data/default_config.json
View file @
a166c390
...
@@ -110,6 +110,7 @@
...
@@ -110,6 +110,7 @@
"challonge"
:
{
"challonge"
:
{
"enabled"
:
false
,
"enabled"
:
false
,
"post_detailed_score"
:
true
,
"post_detailed_score"
:
true
,
"cache_ttl"
:
60000
,
"api_key"
:
"123"
,
"api_key"
:
"123"
,
"tournament_id"
:
"456"
"tournament_id"
:
"456"
},
},
...
...
ygopro-server.coffee
View file @
a166c390
...
@@ -271,12 +271,13 @@ if settings.modules.challonge.enabled
...
@@ -271,12 +271,13 @@ if settings.modules.challonge.enabled
challonge
=
require
(
'challonge'
).
createClient
({
challonge
=
require
(
'challonge'
).
createClient
({
apiKey
:
settings
.
modules
.
challonge
.
api_key
apiKey
:
settings
.
modules
.
challonge
.
api_key
})
})
challonge_cache
=
[]
if
settings
.
modules
.
challonge
.
cache_ttl
challonge_cache
=
[]
challonge_queue_callbacks
=
[[],
[]]
challonge_queue_callbacks
=
[[],
[]]
is_requesting
=
[
false
,
false
]
is_requesting
=
[
false
,
false
]
get_callback
=
(
challonge_type
,
_callback
)
->
get_callback
=
(
challonge_type
,
_callback
)
->
return
((
err
,
data
)
->
return
((
err
,
data
)
->
if
!
err
and
data
if
settings
.
modules
.
challonge
.
cache_ttl
and
!
err
and
data
challonge_cache
[
challonge_type
]
=
data
challonge_cache
[
challonge_type
]
=
data
_callback
(
err
,
data
)
_callback
(
err
,
data
)
while
challonge_queue_callbacks
[
challonge_type
].
length
while
challonge_queue_callbacks
[
challonge_type
].
length
...
@@ -286,7 +287,7 @@ if settings.modules.challonge.enabled
...
@@ -286,7 +287,7 @@ if settings.modules.challonge.enabled
return
return
)
)
challonge
.
participants
.
_index
=
(
_data
)
->
challonge
.
participants
.
_index
=
(
_data
)
->
if
challonge_cache
[
0
]
if
settings
.
modules
.
challonge
.
cache_ttl
and
challonge_cache
[
0
]
_data
.
callback
(
null
,
challonge_cache
[
0
])
_data
.
callback
(
null
,
challonge_cache
[
0
])
else
if
is_requesting
[
0
]
else
if
is_requesting
[
0
]
challonge_queue_callbacks
[
0
].
push
(
_data
.
callback
)
challonge_queue_callbacks
[
0
].
push
(
_data
.
callback
)
...
@@ -296,7 +297,7 @@ if settings.modules.challonge.enabled
...
@@ -296,7 +297,7 @@ if settings.modules.challonge.enabled
challonge
.
participants
.
index
(
_data
)
challonge
.
participants
.
index
(
_data
)
return
return
challonge
.
matches
.
_index
=
(
_data
)
->
challonge
.
matches
.
_index
=
(
_data
)
->
if
challonge_cache
[
1
]
if
settings
.
modules
.
challonge
.
cache_ttl
and
challonge_cache
[
1
]
_data
.
callback
(
null
,
challonge_cache
[
1
])
_data
.
callback
(
null
,
challonge_cache
[
1
])
else
if
is_requesting
[
1
]
else
if
is_requesting
[
1
]
challonge_queue_callbacks
[
1
].
push
(
_data
.
callback
)
challonge_queue_callbacks
[
1
].
push
(
_data
.
callback
)
...
@@ -306,8 +307,9 @@ if settings.modules.challonge.enabled
...
@@ -306,8 +307,9 @@ if settings.modules.challonge.enabled
challonge
.
matches
.
index
(
_data
)
challonge
.
matches
.
index
(
_data
)
return
return
refresh_challonge_cache
=
()
->
refresh_challonge_cache
=
()
->
challonge_cache
[
0
]
=
null
if
settings
.
modules
.
challonge
.
cache_ttl
challonge_cache
[
1
]
=
null
challonge_cache
[
0
]
=
null
challonge_cache
[
1
]
=
null
return
return
refresh_challonge_cache
()
refresh_challonge_cache
()
# challonge.participants._index({
# challonge.participants._index({
...
@@ -322,7 +324,8 @@ if settings.modules.challonge.enabled
...
@@ -322,7 +324,8 @@ if settings.modules.challonge.enabled
# return
# return
# )
# )
# })
# })
setInterval
(
refresh_challonge_cache
,
60000
)
if
settings
.
modules
.
challonge
.
cache_ttl
setInterval
(
refresh_challonge_cache
,
settings
.
modules
.
challonge
.
cache_ttl
)
# 获取可用内存
# 获取可用内存
memory_usage
=
0
memory_usage
=
0
...
...
ygopro-server.js
View file @
a166c390
...
@@ -318,13 +318,15 @@
...
@@ -318,13 +318,15 @@
challonge
=
require
(
'
challonge
'
).
createClient
({
challonge
=
require
(
'
challonge
'
).
createClient
({
apiKey
:
settings
.
modules
.
challonge
.
api_key
apiKey
:
settings
.
modules
.
challonge
.
api_key
});
});
challonge_cache
=
[];
if
(
settings
.
modules
.
challonge
.
cache_ttl
)
{
challonge_cache
=
[];
}
challonge_queue_callbacks
=
[[],
[]];
challonge_queue_callbacks
=
[[],
[]];
is_requesting
=
[
false
,
false
];
is_requesting
=
[
false
,
false
];
get_callback
=
function
(
challonge_type
,
_callback
)
{
get_callback
=
function
(
challonge_type
,
_callback
)
{
return
(
function
(
err
,
data
)
{
return
(
function
(
err
,
data
)
{
var
cur_callback
;
var
cur_callback
;
if
(
!
err
&&
data
)
{
if
(
settings
.
modules
.
challonge
.
cache_ttl
&&
!
err
&&
data
)
{
challonge_cache
[
challonge_type
]
=
data
;
challonge_cache
[
challonge_type
]
=
data
;
}
}
_callback
(
err
,
data
);
_callback
(
err
,
data
);
...
@@ -336,7 +338,7 @@
...
@@ -336,7 +338,7 @@
});
});
};
};
challonge
.
participants
.
_index
=
function
(
_data
)
{
challonge
.
participants
.
_index
=
function
(
_data
)
{
if
(
challonge_cache
[
0
])
{
if
(
settings
.
modules
.
challonge
.
cache_ttl
&&
challonge_cache
[
0
])
{
_data
.
callback
(
null
,
challonge_cache
[
0
]);
_data
.
callback
(
null
,
challonge_cache
[
0
]);
}
else
if
(
is_requesting
[
0
])
{
}
else
if
(
is_requesting
[
0
])
{
challonge_queue_callbacks
[
0
].
push
(
_data
.
callback
);
challonge_queue_callbacks
[
0
].
push
(
_data
.
callback
);
...
@@ -347,7 +349,7 @@
...
@@ -347,7 +349,7 @@
}
}
};
};
challonge
.
matches
.
_index
=
function
(
_data
)
{
challonge
.
matches
.
_index
=
function
(
_data
)
{
if
(
challonge_cache
[
1
])
{
if
(
settings
.
modules
.
challonge
.
cache_ttl
&&
challonge_cache
[
1
])
{
_data
.
callback
(
null
,
challonge_cache
[
1
]);
_data
.
callback
(
null
,
challonge_cache
[
1
]);
}
else
if
(
is_requesting
[
1
])
{
}
else
if
(
is_requesting
[
1
])
{
challonge_queue_callbacks
[
1
].
push
(
_data
.
callback
);
challonge_queue_callbacks
[
1
].
push
(
_data
.
callback
);
...
@@ -358,11 +360,15 @@
...
@@ -358,11 +360,15 @@
}
}
};
};
refresh_challonge_cache
=
function
()
{
refresh_challonge_cache
=
function
()
{
challonge_cache
[
0
]
=
null
;
if
(
settings
.
modules
.
challonge
.
cache_ttl
)
{
challonge_cache
[
1
]
=
null
;
challonge_cache
[
0
]
=
null
;
challonge_cache
[
1
]
=
null
;
}
};
};
refresh_challonge_cache
();
refresh_challonge_cache
();
setInterval
(
refresh_challonge_cache
,
60000
);
if
(
settings
.
modules
.
challonge
.
cache_ttl
)
{
setInterval
(
refresh_challonge_cache
,
settings
.
modules
.
challonge
.
cache_ttl
);
}
}
}
memory_usage
=
0
;
memory_usage
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment