Przeglądaj źródła

Merge pull request #71 from gabriel-samfira/compress-task-info

Compress Bson fields
Gabriel 6 lat temu
rodzic
commit
ad24529090
1 zmienionych plików z 9 dodań i 2 usunięć
  1. 9 2
      coriolis/db/sqlalchemy/types.py

+ 9 - 2
coriolis/db/sqlalchemy/types.py

@@ -14,6 +14,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
+import zlib
 
 from oslo_serialization import jsonutils
 from sqlalchemy.dialects import mysql
@@ -54,12 +55,18 @@ class Json(LongText):
 class Bson(Blob):
 
     def process_bind_param(self, value, dialect):
-        return jsonutils.dumps(value).encode('utf-8')
+        return zlib.compress(
+                jsonutils.dumps(value).encode('utf-8'))
 
     def process_result_value(self, value, dialect):
         if value is None:
             return None
-        return jsonutils.loads(value.decode('utf-8'))
+        data = None
+        try:
+            data = zlib.decompress(value)
+        except:
+            data = value
+        return jsonutils.loads(data)
 
 
 class List(types.TypeDecorator):