mirror of
				https://github.com/matrix-org/synapse.git
				synced 2025-11-04 10:11:05 +01:00 
			
		
		
		
	Avoid locking pushers table on upsert
				
					
				
			Now that _simple_upsert will retry on IntegrityError, we don't need to lock the table.
This commit is contained in:
		
							parent
							
								
									10aaa1bc15
								
							
						
					
					
						commit
						7ab2b69e18
					
				@ -204,16 +204,16 @@ class PusherStore(SQLBaseStore):
 | 
				
			|||||||
                   pushkey, pushkey_ts, lang, data, last_stream_ordering,
 | 
					                   pushkey, pushkey_ts, lang, data, last_stream_ordering,
 | 
				
			||||||
                   profile_tag=""):
 | 
					                   profile_tag=""):
 | 
				
			||||||
        with self._pushers_id_gen.get_next() as stream_id:
 | 
					        with self._pushers_id_gen.get_next() as stream_id:
 | 
				
			||||||
            def f(txn):
 | 
					            # no need to lock because `pushers` has a unique key on
 | 
				
			||||||
                newly_inserted = self._simple_upsert_txn(
 | 
					            # (app_id, pushkey, user_name) so _simple_upsert will retry
 | 
				
			||||||
                    txn,
 | 
					            newly_inserted = yield self._simple_upsert(
 | 
				
			||||||
                    "pushers",
 | 
					                table="pushers",
 | 
				
			||||||
                    {
 | 
					                keyvalues={
 | 
				
			||||||
                    "app_id": app_id,
 | 
					                    "app_id": app_id,
 | 
				
			||||||
                    "pushkey": pushkey,
 | 
					                    "pushkey": pushkey,
 | 
				
			||||||
                    "user_name": user_id,
 | 
					                    "user_name": user_id,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                    {
 | 
					                values={
 | 
				
			||||||
                    "access_token": access_token,
 | 
					                    "access_token": access_token,
 | 
				
			||||||
                    "kind": kind,
 | 
					                    "kind": kind,
 | 
				
			||||||
                    "app_display_name": app_display_name,
 | 
					                    "app_display_name": app_display_name,
 | 
				
			||||||
@ -225,13 +225,14 @@ class PusherStore(SQLBaseStore):
 | 
				
			|||||||
                    "profile_tag": profile_tag,
 | 
					                    "profile_tag": profile_tag,
 | 
				
			||||||
                    "id": stream_id,
 | 
					                    "id": stream_id,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 | 
					                desc="add_pusher",
 | 
				
			||||||
 | 
					                lock=False,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if newly_inserted:
 | 
					            if newly_inserted:
 | 
				
			||||||
                # get_if_user_has_pusher only cares if the user has
 | 
					                # get_if_user_has_pusher only cares if the user has
 | 
				
			||||||
                # at least *one* pusher.
 | 
					                # at least *one* pusher.
 | 
				
			||||||
                    txn.call_after(self.get_if_user_has_pusher.invalidate, (user_id,))
 | 
					                self.get_if_user_has_pusher.invalidate(user_id,)
 | 
				
			||||||
 | 
					 | 
				
			||||||
            yield self.runInteraction("add_pusher", f)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @defer.inlineCallbacks
 | 
					    @defer.inlineCallbacks
 | 
				
			||||||
    def delete_pusher_by_app_id_pushkey_user_id(self, app_id, pushkey, user_id):
 | 
					    def delete_pusher_by_app_id_pushkey_user_id(self, app_id, pushkey, user_id):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user