如何增加firebase数据库读取时间并防止Nginx超时

如何增加firebase数据库读取时间并防止Nginx超时,firebase,go,firebase-realtime-database,concurrency,firebase-cloud-messaging,Firebase,Go,Firebase Realtime Database,Concurrency,Firebase Cloud Messaging,上下文:我尝试建立一个聊天服务。在聊天室服务中,我有(比如:50000多个)聊天室。 我有20个管理员可以访问一些特定的聊天室(比如:可以访问大约5000个聊天室)。因此,我想创建一些功能,这样我就可以添加新的管理员,并根据我的查询获取聊天室列表(比如:我从我的查询中获得了5000个聊天室),使用一个端点将新的管理员添加到5000个聊天室中。我正在使用Golang和Firebase //GetAdmin user take a userID and it's return a user. fun

上下文:我尝试建立一个聊天服务。在聊天室服务中,我有(比如:50000多个)聊天室。 我有20个管理员可以访问一些特定的聊天室(比如:可以访问大约5000个聊天室)。因此,我想创建一些功能,这样我就可以添加新的管理员,并根据我的查询获取聊天室列表(比如:我从我的查询中获得了5000个聊天室),使用一个端点将新的管理员添加到5000个聊天室中。我正在使用Golang和Firebase

//GetAdmin user take a userID and it's return a user.
func GetAdminUser(userID int) (user *User, err error) {
    // It will query on the database 
    // then return the a user
    return user, nil
}
问题是,当我传递患者列表并尝试从firebase数据库中读取患者的主题时,阅读大约需要20分钟。因此,它将在Nginx上暂停

是否有任何方法可以使用go并发提高firebase读取时间,或者有任何其他方法可以提高firebase的读取并添加它们,而不会导致任何超时错误

func AddNewAdminToPatientTopics(ctx context.Context, user User, patients []User) error {
    for _, patient := range patients {
        oldTopics := firebase.database.NewRef(fmt.Sprintf("USER_TOPICS/%d", patient.ID))
        for topicID, t := range topics {
            newUserTopics := firebase.database.NewRef(fmt.Sprintf("USER_TOPICS/%d/%s", user.ID, topicID))

            // Add this new admin as a participant in this topic
            topic := firebase.database.NewRef(fmt.Sprintf("TOPICS/%s/Participants/%d", topicID, user.ID))
            participant := &Participant{
                UserID: strconv.Itoa(user.ID),
                LastTimeSeenOnline: time.Now().Unix(),
                .......
            }
            err = topic.Set(ctx, participant)
            if err != nil {
                return err
            }
        }
    }

    return nil
}


func AddManager(w http.ResponseWriter, r *http.Request) {
    // Don't worry about error, I handle them gracefully

    // Get User
    user, err := GetAdminUser(UserID)

    // get patients list
    // Say, In this case you we have 5000+ patients
    patients, err := GetPatients(user.CustomerID)


    // Join this user to all chat rooms that the first admin has
    err = AddNewAdminToTopics(context.Background(), *user, patients)
}

Routers: 

http.HandleFunc("chat/managers/new/add", Post).Then(clinic.AddManager))

请不要在真实数据库上执行巨大的读写操作。当服务器正在处理巨大的读/写操作时,它不会为来自客户端的请求提供服务

对于这种类型的处理,我强烈建议在Firebase控制台中设置自动备份,然后对该备份中的原始数据执行该操作。这样,您可以优化处理数据的方式,而不依赖于Firebase数据库服务器的响应时间

当然,写操作仍然依赖于Firebase服务器。我会考虑在合理大小的多点更新中做这件事,确保每一个多点更新最多不超过几秒钟。