Skip to content

Commit 5888794

Browse files
committed
getByID methods no longer synchronize with their cache
Fixes #1 (comment)
1 parent 809ca06 commit 5888794

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

src/main/java/io/codebottle/api/CodeBottle.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ public Optional<String> getToken() {
4141
}
4242

4343
public Optional<Language> getLanguageByID(String id) {
44-
synchronized (languageCache) {
45-
return Optional.ofNullable(languageCache.get(id));
46-
}
44+
return Optional.ofNullable(languageCache.get(id));
4745
}
4846

4947
public Collection<Language> getLanguages() {
50-
synchronized (languageCache) {
51-
return languageCache.values();
52-
}
48+
return languageCache.values();
5349
}
5450

5551
public CompletableFuture<Language> requestLanguageByID(String id) {
@@ -89,15 +85,11 @@ public CompletableFuture<Collection<Language>> requestLanguages() {
8985
}
9086

9187
public Optional<Category> getCategoryByID(String id) {
92-
synchronized (categoryCache) {
93-
return Optional.ofNullable(categoryCache.get(id));
94-
}
88+
return Optional.ofNullable(categoryCache.get(id));
9589
}
9690

9791
public Collection<Category> getCategories() {
98-
synchronized (categoryCache) {
99-
return categoryCache.values();
100-
}
92+
return categoryCache.values();
10193
}
10294

10395
public CompletableFuture<Category> requestCategoryByID(String id) {
@@ -137,15 +129,11 @@ public CompletableFuture<Collection<Category>> requestCategories() {
137129
}
138130

139131
public Optional<Snippet> getSnippetByID(String id) {
140-
synchronized (snippetCache) {
141-
return Optional.ofNullable(snippetCache.get(id));
142-
}
132+
return Optional.ofNullable(snippetCache.get(id));
143133
}
144134

145135
public Collection<Snippet> getSnippets() {
146-
synchronized (snippetCache) {
147-
return snippetCache.values();
148-
}
136+
return snippetCache.values();
149137
}
150138

151139
public CompletableFuture<Snippet> requestSnippetByID(String id) {
@@ -185,19 +173,15 @@ public CompletableFuture<Collection<Snippet>> requestSnippets() {
185173
}
186174

187175
public Optional<Snippet.Revision> getSnippetRevisionByID(String snippetId, int id) throws IndexOutOfBoundsException {
188-
synchronized (snippetCache) {
189-
return Optional.ofNullable(snippetCache.get(snippetId))
190-
.flatMap(snippet -> snippet.getRevisionByID(id));
191-
}
176+
return Optional.ofNullable(snippetCache.get(snippetId))
177+
.flatMap(snippet -> snippet.getRevisionByID(id));
192178
}
193179

194180
public Collection<Snippet.Revision> getSnippetRevisions() {
195-
synchronized (snippetCache) {
196-
return snippetCache.values()
197-
.stream()
198-
.flatMap(snippet -> snippet.getRevisions().stream())
199-
.collect(Collectors.toList());
200-
}
181+
return snippetCache.values()
182+
.stream()
183+
.flatMap(snippet -> snippet.getRevisions().stream())
184+
.collect(Collectors.toList());
201185
}
202186

203187
public CompletableFuture<Snippet.Revision> requestSnippetRevision(String snippetId, int id) {

src/main/java/io/codebottle/api/model/Snippet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ public Snippet update(JsonNode data) {
103103
}
104104

105105
public Optional<Revision> getRevisionByID(int id) throws IndexOutOfBoundsException {
106-
synchronized (revisions) {
107-
return Optional.ofNullable(revisions.get(id));
108-
}
106+
return Optional.ofNullable(revisions.get(id));
109107
}
110108

111109
public Collection<Revision> getRevisions() {

0 commit comments

Comments
 (0)