윤영준 윤영준 2024-07-17
first commit of refactoring of data transaction - gps data, attempt to fix problems that 1. data being sent too often, 2. in previous method, the data insert operation happens too often. this commit is trying to fix it by 1. data being sent every 15sec (or more) not every sec, 2. reformatted gps data so that data transaction will cost a lot less bandwidth and 3. insertion operation has been replaced with copy, which is more apt for bulk row appendage operation.
@7e2552bab68ce2a243aac69883b5ef699321fe10
action.py
--- action.py
+++ action.py
@@ -186,7 +186,7 @@
             user_id = decoded_token['id']
         
         # GPS 데이터베이스에 삽입
-        db.insert_gps_data(trip_id, location_x, location_y, user_id, timestamp)
+        db.insert_gps_data(data_csv_block, columns)
         return jsonify({'result': 'success'})
             
             
database/database.py
--- database/database.py
+++ database/database.py
@@ -203,6 +203,7 @@
         
         data = StringIO(csv_block)
         
+        # using COPY instead of INSERT to do even less operation per data. 
         cur.copy_from(data, 'gps_data', sep=',' columns = columns)
         self.conn.commit()
         cur.close()
Add a comment
List