So here is my issue. I have a requirement to essentially seed a Discourse production instance with around 200 posts at a time from a plugin admin action. These posts will be ‘created by’ 1 of 10 different regular users. The reason it’s a plugin action is because the users of this particular instance have a team of moderators they want to train up, and wanted some test posts to train them on, and the ability to seed more when they need them.
I got this working fine by passing skip_validations: true to PostCreator.new, however now there’s a requirement that some of the created posts are also flagged.
I first attempted to disable the RateLimiter but that was causing my action to crash the server process eventually, possibly when I was trying to turn it back on, and then I realised it probably wasn’t a good idea anyway.
So my question is, is there a better way to bypass the rate limiter when running some arbitrary code i.e. something like:
RateLimiter.bypass do
# run some code not affected by the rate limiter
end
Or do I need to basically just need to copy most of what the PostActionCreator is doing but leave out the troublesome line?
Any help would be greatly appreciated! I’m still absorbing a lot of the Discourse code so I’m aware I’ve probably missed something that makes this a lot easier!
Hai capito? Modificare il file yaml non è l’ideale perché richiede una ricompilazione. Non ho abbastanza familiarità con rails/discourse per capire come disabilitarlo temporaneamente nella console.
Sto cercando di importare 60.000 utenti tramite API il più velocemente possibile senza dover ricostruire. Ho anche provato su un’installazione di test ad aumentare il limite dell’API ADMIN tramite YAML, ma non sembrava funzionare, ma forse ho fatto qualcosa di sbagliato. (Sto eseguendo le importazioni sul container, quindi il throttling HTTP non dovrebbe applicarsi).
Ma puoi entrare nel container e modificare /var/www/discourse/config/discourse.conf e impostare quelle variabili lì e poi fare un sv restart unicorn (o forse sv reload unicorn). Probabilmente vorrai fare qualcosa come apt-get update; apt-get install -y vim per avere un editor.
Strano. Quando visualizzo il file di configurazione, il nuovo limite è già impostato. Quindi l’aggiornamento YAML ha funzionato:
max_admin_api_reqs_per_key_per_minute = '6000'
Ma non sembra funzionare. C’è ancora una limitazione di 60 al minuto. Quando limito le richieste a 60 al minuto, la maggior parte passa ma a causa del jitter alcune attivano ancora il rate limiter:
{'success': True, 'active': True, 'message': 'Il tuo account è stato attivato e pronto per l'uso.', 'user_id': 3596}
{'success': False, 'message': ' Le nuove registrazioni non sono consentite dal tuo indirizzo IP (limite massimo raggiunto). Contatta un membro dello staff.', 'errors': {'ip_address': ['Le nuove registrazioni non sono consentite dal tuo indirizzo IP (limite massimo raggiunto). Contatta un membro dello staff.']}, 'values': {'name': None, 'username': 'asdfd', 'email': 'user@domain.com'}, 'is_developer': False}
{'success': True, 'active': True, 'message': 'Il tuo account è stato attivato e pronto per l'uso.', 'user_id': 3597}
Penso che sia correlato a un altro limite: penso che sia il limite massimo di registrazioni da un IP che sta raggiungendo, ma non capisco perché dopo aver raggiunto questo limite non blocchi permanentemente. Possibilmente un bug in questo limite anti-spam?
Se tutti quegli utenti hanno lo stesso IP, allora scommetto che hai ragione. Penso che la soluzione sia cambiare quell’impostazione o dare alle persone indirizzi IP fasulli come 127.0.0.x (o forse usare IPv6 per renderlo più facile?)
Penso che stia rilevando da dove viene effettuata la richiesta (computer host), ma posso aggirarlo aggiungendo un utente TL2 sullo stesso indirizzo IP (o modificare il limite IP).
Sì, ci proverò. Ma non mi è chiaro come dovrei eseguire lo script, dove devo copiarlo e come devo eseguirlo (una volta che avrò messo il CSV nei posti giusti)?
Come follow-up, dato lo sforzo per comprendere gli script e Ruby, ecc. e le probabili prestazioni, ho intrapreso un’altra strada e ho aggirato tutti i limiti scrivendo direttamente nel database usando SQL. In questo modo sono stato in grado di ottenere diverse migliaia di inserimenti al secondo.
C’era un argomento che chiedeva quali tabelle fossero necessarie, ora è chiuso, quindi rispondo qui che ho modificato le seguenti tabelle per inserire gli utenti: