@@ -16,7 +16,6 @@ import (
16
16
"golang.org/x/pkgsite/internal"
17
17
"golang.org/x/pkgsite/internal/database"
18
18
"golang.org/x/pkgsite/internal/derrors"
19
- "golang.org/x/pkgsite/internal/experiment"
20
19
"golang.org/x/pkgsite/internal/middleware"
21
20
"golang.org/x/pkgsite/internal/stdlib"
22
21
"golang.org/x/pkgsite/internal/version"
@@ -39,19 +38,16 @@ func (db *DB) GetUnitMeta(ctx context.Context, fullPath, requestedModulePath, re
39
38
defer derrors .WrapStack (& err , "DB.GetUnitMeta(ctx, %q, %q, %q)" , fullPath , requestedModulePath , requestedVersion )
40
39
defer middleware .ElapsedStat (ctx , "GetUnitMeta" )()
41
40
42
- if experiment .IsActive (ctx , internal .ExperimentUnitMetaWithLatest ) {
43
- modulePath := requestedModulePath
44
- version := requestedVersion
45
- var lmv * internal.LatestModuleVersions
46
- if requestedVersion == internal .LatestVersion {
47
- modulePath , version , lmv , err = db .getLatestUnitVersion (ctx , fullPath , requestedModulePath )
48
- if err != nil {
49
- return nil , err
50
- }
41
+ modulePath := requestedModulePath
42
+ version := requestedVersion
43
+ var lmv * internal.LatestModuleVersions
44
+ if requestedVersion == internal .LatestVersion {
45
+ modulePath , version , lmv , err = db .getLatestUnitVersion (ctx , fullPath , requestedModulePath )
46
+ if err != nil {
47
+ return nil , err
51
48
}
52
- return db .getUnitMetaWithKnownLatestVersion (ctx , fullPath , modulePath , version , lmv )
53
49
}
54
- return db .legacyGetUnitMeta (ctx , fullPath , requestedModulePath , requestedVersion )
50
+ return db .getUnitMetaWithKnownLatestVersion (ctx , fullPath , modulePath , version , lmv )
55
51
}
56
52
57
53
func (db * DB ) getUnitMetaWithKnownLatestVersion (ctx context.Context , fullPath , modulePath , version string , lmv * internal.LatestModuleVersions ) (_ * internal.UnitMeta , err error ) {
@@ -225,131 +221,6 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul
225
221
return modulePath , latestVersion , nil , nil
226
222
}
227
223
228
- func (db * DB ) legacyGetUnitMeta (ctx context.Context , fullPath , requestedModulePath , requestedVersion string ) (_ * internal.UnitMeta , err error ) {
229
- defer derrors .WrapStack (& err , "DB.legacyGetUnitMeta(ctx, %q, %q, %q)" , fullPath , requestedModulePath , requestedVersion )
230
-
231
- var (
232
- q string
233
- args []interface {}
234
- )
235
- q , args , err = getUnitMetaQuery (fullPath , requestedModulePath , requestedVersion ).PlaceholderFormat (squirrel .Dollar ).ToSql ()
236
- if err != nil {
237
- return nil , fmt .Errorf ("squirrel.ToSql: %v" , err )
238
- }
239
- var (
240
- licenseTypes []string
241
- licensePaths []string
242
- um = internal.UnitMeta {Path : fullPath }
243
- )
244
- err = db .db .QueryRow (ctx , q , args ... ).Scan (
245
- & um .ModulePath ,
246
- & um .Version ,
247
- & um .CommitTime ,
248
- jsonbScanner {& um .SourceInfo },
249
- & um .HasGoMod ,
250
- & um .ModuleInfo .IsRedistributable ,
251
- & um .Name ,
252
- & um .IsRedistributable ,
253
- pq .Array (& licenseTypes ),
254
- pq .Array (& licensePaths ))
255
- switch err {
256
- case sql .ErrNoRows :
257
- return nil , derrors .NotFound
258
- case nil :
259
- lics , err := zipLicenseMetadata (licenseTypes , licensePaths )
260
- if err != nil {
261
- return nil , err
262
- }
263
-
264
- if db .bypassLicenseCheck {
265
- um .IsRedistributable = true
266
- }
267
-
268
- um .Licenses = lics
269
- if err := populateLatestInfo (ctx , db , & um .ModuleInfo ); err != nil {
270
- return nil , err
271
- }
272
- return & um , nil
273
- default :
274
- return nil , err
275
- }
276
- }
277
-
278
- func getUnitMetaQuery (fullPath , requestedModulePath , requestedVersion string ) squirrel.SelectBuilder {
279
- query := squirrel .Select (
280
- "m.module_path" ,
281
- "m.version" ,
282
- "m.commit_time" ,
283
- "m.source_info" ,
284
- "m.has_go_mod" ,
285
- "m.redistributable" ,
286
- "u.name" ,
287
- "u.redistributable" ,
288
- "u.license_types" ,
289
- "u.license_paths" ,
290
- )
291
- if requestedVersion != internal .LatestVersion {
292
- query = query .From ("modules m" ).
293
- Join ("units u on u.module_id = m.id" ).
294
- Join ("paths p ON p.id = u.path_id" ).Where (squirrel.Eq {"p.path" : fullPath })
295
- if requestedModulePath != internal .UnknownModulePath {
296
- query = query .Where (squirrel.Eq {"m.module_path" : requestedModulePath })
297
- }
298
- if internal .DefaultBranches [requestedVersion ] {
299
- query = query .Join ("version_map vm ON m.id = vm.module_id" ).Where ("vm.requested_version = ? " , requestedVersion )
300
- } else if requestedVersion != internal .LatestVersion {
301
- query = query .Where (squirrel.Eq {"version" : requestedVersion })
302
- }
303
- return orderByLatest (query ).Limit (1 )
304
- }
305
-
306
- // Use a nested select to fetch the latest version of the unit, then JOIN
307
- // on units to fetch other relevant information. This allows us to use the
308
- // index on units.id and paths.path to get the latest path. We can then
309
- // look up only the relevant information from the units table.
310
- nestedSelect := orderByLatest (squirrel .Select (
311
- "m.id" ,
312
- "m.module_path" ,
313
- "m.version" ,
314
- "m.commit_time" ,
315
- "m.source_info" ,
316
- "m.has_go_mod" ,
317
- "m.redistributable" ,
318
- "u.id AS unit_id" ,
319
- ).From ("modules m" ).
320
- Join ("units u ON u.module_id = m.id" ).
321
- Join ("paths p ON p.id = u.path_id" ).
322
- Where (squirrel.Eq {"p.path" : fullPath }))
323
- if requestedModulePath != internal .UnknownModulePath {
324
- nestedSelect = nestedSelect .Where (squirrel.Eq {"m.module_path" : requestedModulePath })
325
- }
326
- nestedSelect = nestedSelect .Limit (1 )
327
- return query .From ("units u" ).JoinClause (nestedSelect .Prefix ("JOIN (" ).Suffix (") m ON u.id = m.unit_id" ))
328
- }
329
-
330
- // orderByLatest orders paths according to the go command.
331
- // Versions are ordered by:
332
- // (1) release (non-incompatible)
333
- // (2) prerelease (non-incompatible)
334
- // (3) release, incompatible
335
- // (4) prerelease, incompatible
336
- // (5) pseudo
337
- // They are then sorted based on semver, then decreasing module path length (so
338
- // that nested modules are preferred).
339
- func orderByLatest (q squirrel.SelectBuilder ) squirrel.SelectBuilder {
340
- return q .OrderBy (
341
- `CASE
342
- WHEN m.version_type = 'release' AND NOT m.incompatible THEN 1
343
- WHEN m.version_type = 'prerelease' AND NOT m.incompatible THEN 2
344
- WHEN m.version_type = 'release' THEN 3
345
- WHEN m.version_type = 'prerelease' THEN 4
346
- ELSE 5
347
- END` ,
348
- "m.series_path DESC" ,
349
- "m.sort_version DESC" ,
350
- ).PlaceholderFormat (squirrel .Dollar )
351
- }
352
-
353
224
// GetUnit returns a unit from the database, along with all of the data
354
225
// associated with that unit.
355
226
func (db * DB ) GetUnit (ctx context.Context , um * internal.UnitMeta , fields internal.FieldSet ) (_ * internal.Unit , err error ) {
0 commit comments