[Bf-extensions-cvs] [e50f22c6] blender-v2.91-release: BlenderKit: fix ratings

Vilém Duha noreply at git.blender.org
Sun Oct 25 23:09:59 CET 2020


Commit: e50f22c6f2d1d8180159417aa1862927cbf4c309
Author: Vilém Duha
Date:   Thu Oct 22 22:59:30 2020 +0200
Branches: blender-v2.91-release
https://developer.blender.org/rBAe50f22c6f2d1d8180159417aa1862927cbf4c309

BlenderKit: fix ratings

Ratings coul be sent more than once with the fast rate operator, now should be fixed by stashing and delaying all requests and only doing one with a delay.

(cherry picked from commit 67b96d2fecaba6bac60663d401a54de7d1bd683f)

===================================================================

M	blenderkit/ratings.py
M	blenderkit/tasks_queue.py

===================================================================

diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index ef6cc6a8..b6ad0185 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -124,7 +124,7 @@ def update_ratings_quality(self, context):
 
     if bkit_ratings.rating_quality > 0.1:
         ratings = [('quality', bkit_ratings.rating_quality)]
-        tasks_queue.add_task((send_rating_to_thread_quality, (url, ratings, headers)), wait=1, only_last=True)
+        tasks_queue.add_task((send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, only_last=True)
 
 
 def update_ratings_work_hours(self, context):
@@ -142,7 +142,7 @@ def update_ratings_work_hours(self, context):
 
     if bkit_ratings.rating_work_hours > 0.05:
         ratings = [('working_hours', round(bkit_ratings.rating_work_hours, 1))]
-        tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=1, only_last=True)
+        tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, only_last=True)
 
 
 def upload_rating(asset):
@@ -159,9 +159,12 @@ def upload_rating(asset):
     ]
 
     if bkit_ratings.rating_quality > 0.1:
-        ratings.append(('quality', bkit_ratings.rating_quality))
+        ratings = (('quality', bkit_ratings.rating_quality),)
+        tasks_queue.add_task((send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, only_last=True)
     if bkit_ratings.rating_work_hours > 0.1:
-        ratings.append(('working_hours', round(bkit_ratings.rating_work_hours, 1)))
+        ratings=(('working_hours', round(bkit_ratings.rating_work_hours, 1)),)
+        tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, only_last=True)
+
 
     thread = threading.Thread(target=upload_rating_thread, args=(url, ratings, headers))
     thread.start()
@@ -327,7 +330,7 @@ class FastRateMenu(Operator):
     rating_quality_ui: EnumProperty(name='rating_quality_ui',
                                     items=stars_enum_callback,
                                     description='Rating stars 0 - 10',
-                                    default=None,
+                                    default=0,
                                     update=update_quality_ui,
                                     )
 
@@ -407,15 +410,18 @@ class FastRateMenu(Operator):
 
         ]
 
-        self.rating_quality = int(self.rating_quality_ui)
+        if self.rating_quality_ui == '':
+            self.rating_quality = 0
+        else:
+            self.rating_quality = int(self.rating_quality_ui)
 
         if self.rating_quality > 0.1:
-            rtgs.append(('quality', self.rating_quality))
-        if self.rating_work_hours > 0.1:
-            rtgs.append(('working_hours', round(self.rating_work_hours, 1)))
+            rtgs = (('quality', self.rating_quality),)
+            tasks_queue.add_task((send_rating_to_thread_quality, (url, rtgs, headers)), wait=2.5, only_last=True)
 
-        thread = threading.Thread(target=upload_rating_thread, args=(url, rtgs, headers))
-        thread.start()
+        if self.rating_work_hours > 0.1:
+            rtgs = (('working_hours', round(self.rating_work_hours, 1)),)
+            tasks_queue.add_task((send_rating_to_thread_work_hours, (url, rtgs, headers)), wait=2.5, only_last=True)
         return {'FINISHED'}
 
     def invoke(self, context, event):
diff --git a/blenderkit/tasks_queue.py b/blenderkit/tasks_queue.py
index 5a327290..c619a7b0 100644
--- a/blenderkit/tasks_queue.py
+++ b/blenderkit/tasks_queue.py
@@ -70,7 +70,11 @@ def queue_worker():
     while not q.empty():
         task = q.get()
         if task.only_last:
-            stashed[task.command] = task
+            #this now makes the keys not only by task, but also first argument.
+            # by now stashing is only used for ratings, where the first argument is url.
+            # This enables fast rating of multiple assets while allowing larger delay for uploading of ratings.
+            # this avoids a duplicate request error on the server
+            stashed[str(task.command)+str(task.arguments[0])] = task
         else:
             back_to_queue.append(task)
     #return tasks to que except for stashed



More information about the Bf-extensions-cvs mailing list