Increase use of pointers in CORPUS package

This commit is contained in:
Fred Boniface
2024-04-10 20:56:13 +01:00
parent 39405e6d6a
commit 3883031e04
4 changed files with 24 additions and 21 deletions

View File

@@ -7,12 +7,12 @@ import (
)
// Puts an array of Corpus Documents into the database
func PutManyCorpus(corpusData []database.CorpusEntry) error {
func PutManyCorpus(corpusData *[]database.CorpusEntry) error {
collection := MongoClient.Database(databaseName).Collection(CorpusCollection)
documents := convertCorpusToInterfaceSlice(corpusData)
_, err := collection.InsertMany(context.Background(), documents)
_, err := collection.InsertMany(context.Background(), *documents)
if err != nil {
return err
}
@@ -22,12 +22,12 @@ func PutManyCorpus(corpusData []database.CorpusEntry) error {
}
// Puts an array of Stations documents into the database
func PutManyStations(stationsData []database.StationEntry) error {
func PutManyStations(stationsData *[]database.StationEntry) error {
collection := MongoClient.Database(databaseName).Collection(StationsCollection)
documents := convertStationsToInterfaceSlice(stationsData)
_, err := collection.InsertMany(context.Background(), documents)
_, err := collection.InsertMany(context.Background(), *documents)
if err != nil {
return err
}
@@ -37,19 +37,19 @@ func PutManyStations(stationsData []database.StationEntry) error {
}
// Converts []database.CorpusEntry types into interface slices required to put them into the database
func convertCorpusToInterfaceSlice(corpusData []database.CorpusEntry) []interface{} {
interfaceSlice := make([]interface{}, len(corpusData))
for i, doc := range corpusData {
func convertCorpusToInterfaceSlice(corpusData *[]database.CorpusEntry) *[]interface{} {
interfaceSlice := make([]interface{}, len(*corpusData))
for i, doc := range *corpusData {
interfaceSlice[i] = doc
}
return interfaceSlice
return &interfaceSlice
}
// Converts []database.StationEntry types into interface slices required to put them into the database
func convertStationsToInterfaceSlice(stationsData []database.StationEntry) []interface{} {
interfaceSlice := make([]interface{}, len(stationsData))
for i, doc := range stationsData {
func convertStationsToInterfaceSlice(stationsData *[]database.StationEntry) *[]interface{} {
interfaceSlice := make([]interface{}, len(*stationsData))
for i, doc := range *stationsData {
interfaceSlice[i] = doc
}
return interfaceSlice
return &interfaceSlice
}