@@ -149,62 +149,44 @@ func (a *moduleDataProvider) getIndexedModuleDatasForRegistryAndIndexedModuleKey
149149 return nil , err
150150 }
151151 indexedModuleDatas := make ([]slicesext.Indexed [bufmodule.ModuleData ], 0 , len (indexedModuleKeys ))
152- if err := graph .WalkNodes (
153- func (
154- moduleKey bufmodule.ModuleKey ,
155- _ []bufmodule.ModuleKey ,
156- _ []bufmodule.ModuleKey ,
157- ) error {
158- // TopoSort will get us both the direct and transitive dependencies for the key.
159- //
160- // The outgoing edge list is just the direct dependencies.
161- //
162- // There is definitely a better way to do this in one pass for all commits with
163- // memoization - this is algorithmically bad.
164- depModuleKeys , err := graph .TopoSort (bufmodule .ModuleKeyToRegistryCommitID (moduleKey ))
165- if err != nil {
166- return err
167- }
168- depModuleKeys = depModuleKeys [:len (depModuleKeys )- 1 ]
169- sort .Slice (
170- depModuleKeys ,
171- func (i int , j int ) bool {
172- return depModuleKeys [i ].FullName ().String () < depModuleKeys [j ].FullName ().String ()
173- },
174- )
152+ for _ , indexedModuleKey := range indexedModuleKeys {
153+ moduleKey := indexedModuleKey .Value
154+ // TopoSort will get us both the direct and transitive dependencies for the key.
155+ depModuleKeys , err := graph .TopoSort (bufmodule .ModuleKeyToRegistryCommitID (moduleKey ))
156+ if err != nil {
157+ return nil , err
158+ }
159+ // Remove this moduleKey from the depModuleKeys.
160+ depModuleKeys = depModuleKeys [:len (depModuleKeys )- 1 ]
161+ sort .Slice (
162+ depModuleKeys ,
163+ func (i int , j int ) bool {
164+ return depModuleKeys [i ].FullName ().String () < depModuleKeys [j ].FullName ().String ()
165+ },
166+ )
175167
176- universalProtoContent , ok := commitIDToUniversalProtoContent [moduleKey .CommitID ()]
177- if ! ok {
178- // We only care to get content for a subset of the graph. If we have something
179- // in the graph without content, we just skip it.
180- return nil
181- }
182- indexedModuleKey , ok := commitIDToIndexedModuleKey [moduleKey .CommitID ()]
183- if ! ok {
184- return syserror .Newf ("could not find indexed ModuleKey for commit ID %q" , uuidutil .ToDashless (moduleKey .CommitID ()))
185- }
186- indexedModuleData := slicesext.Indexed [bufmodule.ModuleData ]{
187- Value : bufmodule .NewModuleData (
188- ctx ,
189- moduleKey ,
190- func () (storage.ReadBucket , error ) {
191- return universalProtoFilesToBucket (universalProtoContent .Files )
192- },
193- func () ([]bufmodule.ModuleKey , error ) { return depModuleKeys , nil },
194- func () (bufmodule.ObjectData , error ) {
195- return universalProtoFileToObjectData (universalProtoContent .V1BufYAMLFile )
196- },
197- func () (bufmodule.ObjectData , error ) {
198- return universalProtoFileToObjectData (universalProtoContent .V1BufLockFile )
199- },
200- ),
201- Index : indexedModuleKey .Index ,
202- }
203- indexedModuleDatas = append (indexedModuleDatas , indexedModuleData )
204- return nil
205- },
206- ); err != nil {
207- return nil , err
168+ universalProtoContent , ok := commitIDToUniversalProtoContent [moduleKey .CommitID ()]
169+ if ! ok {
170+ return nil , syserror .Newf ("could not find universalProtoContent for commit ID %q" , moduleKey .CommitID ())
171+ }
172+ indexedModuleData := slicesext.Indexed [bufmodule.ModuleData ]{
173+ Value : bufmodule .NewModuleData (
174+ ctx ,
175+ moduleKey ,
176+ func () (storage.ReadBucket , error ) {
177+ return universalProtoFilesToBucket (universalProtoContent .Files )
178+ },
179+ func () ([]bufmodule.ModuleKey , error ) { return depModuleKeys , nil },
180+ func () (bufmodule.ObjectData , error ) {
181+ return universalProtoFileToObjectData (universalProtoContent .V1BufYAMLFile )
182+ },
183+ func () (bufmodule.ObjectData , error ) {
184+ return universalProtoFileToObjectData (universalProtoContent .V1BufLockFile )
185+ },
186+ ),
187+ Index : indexedModuleKey .Index ,
188+ }
189+ indexedModuleDatas = append (indexedModuleDatas , indexedModuleData )
208190 }
209191 return indexedModuleDatas , nil
210192}
0 commit comments