- commit
- 73dd9964daf5d5bf4d8f4869c50fdcdc280b68d0
- parent
- 748fe0c4fa73648d4529e42dcd140211192a5f0a
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-06-13 14:39
clear topics at the end of POST/PUT/DELETE
Diffstat
| M | via.go | 19 | +++++++++++++------ |
1 files changed, 13 insertions, 6 deletions
diff --git a/via.go b/via.go
@@ -124,6 +124,15 @@ func (topic *Topic) put(data []byte, lastId int) {
124 124 }
125 125 }
126 126
-1 127 func (topic *Topic) cleanup(key string) {
-1 128 if len(topic.channels) == 0 {
-1 129 if verbose {
-1 130 log.Println("clearing topic", key)
-1 131 }
-1 132 delete(topics, key)
-1 133 }
-1 134 }
-1 135
127 136 func getTopic(key string) *Topic {
128 137 mux.Lock()
129 138 defer mux.Unlock()
@@ -173,12 +182,7 @@ func popChannel(key string, ch chan Msg) {
173 182 delete(topic.channels, ch)
174 183 topic.Unlock()
175 184
176 -1 if len(topic.channels) == 0 {
177 -1 if verbose {
178 -1 log.Println("clearing topic", key)
179 -1 }
180 -1 delete(topics, key)
181 -1 }
-1 185 topic.cleanup(key)
182 186 }
183 187
184 188 func get(w http.ResponseWriter, r *http.Request) {
@@ -231,6 +235,7 @@ func post(w http.ResponseWriter, r *http.Request) {
231 235 }
232 236
233 237 topic := getTopic(r.URL.Path)
-1 238 defer topic.cleanup(r.URL.Path)
234 239
235 240 response := make(map[string]int)
236 241 defer func() {
@@ -256,6 +261,7 @@ func put(w http.ResponseWriter, r *http.Request) {
256 261 }
257 262
258 263 topic := getTopic(r.URL.Path)
-1 264 defer topic.cleanup(r.URL.Path)
259 265
260 266 lastId, err := strconv.Atoi(r.Header.Get("Last-Event-ID"))
261 267 if err != nil {
@@ -284,6 +290,7 @@ func del(w http.ResponseWriter, r *http.Request) {
284 290 }
285 291
286 292 topic := getTopic(r.URL.Path)
-1 293 defer topic.cleanup(r.URL.Path)
287 294
288 295 topic.Lock()
289 296 defer topic.Unlock()