diff --git a/.gitignore b/.gitignore index 628a2f3..79403e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /tmp config.yml -relay_metadata.json \ No newline at end of file +relay_metadata.json +grain.exe \ No newline at end of file diff --git a/web/http.go b/web/http.go index 1f5548c..8631236 100644 --- a/web/http.go +++ b/web/http.go @@ -97,26 +97,33 @@ func PrependDir(dir string, files []string) []string { func FetchTopTenRecentEvents(client *mongo.Client) ([]relay.Event, error) { var results []relay.Event - collection := client.Database("grain").Collection("events") - filter := bson.D{} - opts := options.Find().SetSort(bson.D{{Key: "createdat", Value: -1}}).SetLimit(10) - - cursor, err := collection.Find(context.TODO(), filter, opts) + collections, err := client.Database("grain").ListCollectionNames(context.TODO(), bson.M{}) if err != nil { return nil, err } - defer cursor.Close(context.TODO()) - for cursor.Next(context.TODO()) { - var event relay.Event - if err := cursor.Decode(&event); err != nil { + for _, collectionName := range collections { + collection := client.Database("grain").Collection(collectionName) + 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 } - results = append(results, event) - } + defer cursor.Close(context.TODO()) - if err := cursor.Err(); err != nil { - return nil, err + for cursor.Next(context.TODO()) { + 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 diff --git a/web/views/templates/#layout.html b/web/views/templates/layout.html similarity index 100% rename from web/views/templates/#layout.html rename to web/views/templates/layout.html