mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-10-30 01:26:32 +00:00
hotfix
This commit is contained in:
parent
b761e47abb
commit
81b2eef486
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/tmp
|
/tmp
|
||||||
config.yml
|
config.yml
|
||||||
relay_metadata.json
|
relay_metadata.json
|
||||||
|
grain.exe
|
33
web/http.go
33
web/http.go
@ -97,26 +97,33 @@ func PrependDir(dir string, files []string) []string {
|
|||||||
func FetchTopTenRecentEvents(client *mongo.Client) ([]relay.Event, error) {
|
func FetchTopTenRecentEvents(client *mongo.Client) ([]relay.Event, error) {
|
||||||
var results []relay.Event
|
var results []relay.Event
|
||||||
|
|
||||||
collection := client.Database("grain").Collection("events")
|
collections, err := client.Database("grain").ListCollectionNames(context.TODO(), bson.M{})
|
||||||
filter := bson.D{}
|
|
||||||
opts := options.Find().SetSort(bson.D{{Key: "createdat", Value: -1}}).SetLimit(10)
|
|
||||||
|
|
||||||
cursor, err := collection.Find(context.TODO(), filter, opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close(context.TODO())
|
|
||||||
|
|
||||||
for cursor.Next(context.TODO()) {
|
for _, collectionName := range collections {
|
||||||
var event relay.Event
|
collection := client.Database("grain").Collection(collectionName)
|
||||||
if err := cursor.Decode(&event); err != nil {
|
filter := bson.D{}
|
||||||
|
opts := options.Find().SetSort(bson.D{{Key: "createdat", Value: -1}}).SetLimit(10)
|
||||||
|
|
||||||
|
cursor, err := collection.Find(context.TODO(), filter, opts)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
results = append(results, event)
|
defer cursor.Close(context.TODO())
|
||||||
}
|
|
||||||
|
|
||||||
if err := cursor.Err(); err != nil {
|
for cursor.Next(context.TODO()) {
|
||||||
return nil, err
|
var event relay.Event
|
||||||
|
if err := cursor.Decode(&event); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
results = append(results, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user