
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
... | ... | @@ -186,7 +186,7 @@ |
186 | 186 |
user_id = decoded_token['id'] |
187 | 187 |
|
188 | 188 |
# GPS 데이터베이스에 삽입 |
189 |
- db.insert_gps_data(trip_id, location_x, location_y, user_id, timestamp) |
|
189 |
+ db.insert_gps_data(data_csv_block, columns) |
|
190 | 190 |
return jsonify({'result': 'success'}) |
191 | 191 |
|
192 | 192 |
|
--- database/database.py
+++ database/database.py
... | ... | @@ -203,6 +203,7 @@ |
203 | 203 |
|
204 | 204 |
data = StringIO(csv_block) |
205 | 205 |
|
206 |
+ # using COPY instead of INSERT to do even less operation per data. |
|
206 | 207 |
cur.copy_from(data, 'gps_data', sep=',' columns = columns) |
207 | 208 |
self.conn.commit() |
208 | 209 |
cur.close() |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?