I would move this into a query. Otherwise you can have a race condition. Simply make a query selector so that it does not match if publication is already in the library.