MCPcopy Index your code
hub / github.com/aptly-dev/aptly / apiDBCleanup

Function apiDBCleanup

api/db.go:24–188  ·  view source on GitHub ↗

@Summary DB Cleanup @Description **Cleanup Aptly DB** @Description Database cleanup removes information about unreferenced packages and deletes files in the package pool that aren’t used by packages anymore. @Description It is a good idea to run this command after massive deletion of mirrors, snapsh

(c *gin.Context)

Source from the content-addressed store, hash-verified

22// @Failure 404 {object} Error "Not Found"
23// @Router /api/db/cleanup [post]
24func apiDBCleanup(c *gin.Context) {
25 resources := []string{string(task.AllResourcesKey)}
26 maybeRunTaskInBackground(c, "Clean up db", resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
27 var err error
28
29 collectionFactory := context.NewCollectionFactory()
30
31 // collect information about referenced packages...
32 existingPackageRefs := deb.NewPackageRefList()
33
34 out.Printf("Loading mirrors, local repos, snapshots and published repos...")
35 err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
36 e := collectionFactory.RemoteRepoCollection().LoadComplete(repo)
37 if e != nil {
38 return e
39 }
40 if repo.RefList() != nil {
41 existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
42 }
43
44 return nil
45 })
46 if err != nil {
47 return nil, err
48 }
49
50 err = collectionFactory.LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
51 e := collectionFactory.LocalRepoCollection().LoadComplete(repo)
52 if e != nil {
53 return e
54 }
55
56 if repo.RefList() != nil {
57 existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
58 }
59
60 return nil
61 })
62 if err != nil {
63 return nil, err
64 }
65
66 err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
67 e := collectionFactory.SnapshotCollection().LoadComplete(snapshot)
68 if e != nil {
69 return e
70 }
71
72 existingPackageRefs = existingPackageRefs.Merge(snapshot.RefList(), false, true)
73
74 return nil
75 })
76 if err != nil {
77 return nil, err
78 }
79
80 err = collectionFactory.PublishedRepoCollection().ForEach(func(published *deb.PublishedRepo) error {
81 if published.SourceKind != deb.SourceLocalRepo {

Callers

nothing calls this directly

Calls 15

RemoteRepoCollectionMethod · 0.95
MergeMethod · 0.95
LocalRepoCollectionMethod · 0.95
SnapshotCollectionMethod · 0.95
PackageCollectionMethod · 0.95
LenMethod · 0.95
ForEachMethod · 0.95
NewPackageRefListFunction · 0.92
StrSlicesSubstractFunction · 0.92
HumanBytesFunction · 0.92
maybeRunTaskInBackgroundFunction · 0.85

Tested by

no test coverage detected