scrobbler-ng-utils 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -32,16 +32,18 @@ module Scrobbler
|
|
32
32
|
# @return [boolean]
|
33
33
|
def has?(params={})
|
34
34
|
# Check if there is a matching chache entry with no extra parameters
|
35
|
+
found = false
|
35
36
|
@collection.find(params).each do |doc|
|
36
37
|
if verify(doc, params) then
|
37
38
|
@hits += 1
|
38
|
-
|
39
|
+
found = true
|
40
|
+
break
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
# We have not found a mathing cache entry.
|
43
|
-
@misses += 1
|
44
|
-
|
45
|
+
@misses += 1 unless found
|
46
|
+
found
|
45
47
|
end
|
46
48
|
|
47
49
|
# Store a result into the database.
|
@@ -51,7 +53,7 @@ module Scrobbler
|
|
51
53
|
# @return [void]
|
52
54
|
def set(data, params={})
|
53
55
|
if not has?(params) then
|
54
|
-
|
56
|
+
@collection.insert(params.merge({:xml => data, :timestamp => Time.now.to_i}))
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -60,9 +62,14 @@ module Scrobbler
|
|
60
62
|
# @param [Hash] params
|
61
63
|
# @return [String]
|
62
64
|
def get(params={})
|
65
|
+
found = nil
|
63
66
|
@collection.find(params).each do |doc|
|
64
|
-
|
67
|
+
if verify(doc, params) then
|
68
|
+
found = doc['xml']
|
69
|
+
break
|
70
|
+
end
|
65
71
|
end
|
72
|
+
found
|
66
73
|
end
|
67
74
|
|
68
75
|
# Verify that a specific document matches exactly the request cache.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Scrobbler
|
2
|
+
class Base
|
3
|
+
@@fetch_http_lastcall = 0
|
4
|
+
class << self
|
5
|
+
alias :orig_fetch_http :fetch_http
|
6
|
+
def fetch_http(request_method, paramlist)
|
7
|
+
now = ("%10.6f" % Time.now.to_f).to_f
|
8
|
+
threshold = now - 1
|
9
|
+
if (@@fetch_http_lastcall > threshold) then
|
10
|
+
sleep(now - @@fetch_http_lastcall)
|
11
|
+
end
|
12
|
+
@@fetch_http_lastcall = now
|
13
|
+
return orig_fetch_http(request_method, paramlist)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrobbler-ng-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 3
|
10
|
+
version: 2.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Uwe L. Korn
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-06 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ extra_rdoc_files:
|
|
60
60
|
files:
|
61
61
|
- lib/scrobbler-ng-utils.rb
|
62
62
|
- lib/scrobbler-ng-utils/cache/mongo.rb
|
63
|
+
- lib/scrobbler-ng-utils/misc/rate-limiter.rb
|
63
64
|
- LICENSE
|
64
65
|
- README.rdoc
|
65
66
|
- spec/spec_helper.rb
|