Skip to content

Commit fe04cb7

Browse files
ethanalee-workjba
authored andcommitted
internal/postgres: add skip-symbols list to saveModule
- Modules in the skip-symbols list will not have symbol information inserted into postgres. Change-Id: Ia52b9eb2d7cab662b967fa4a74c40cced0e44be4 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/713060 Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> kokoro-CI: kokoro <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 31e4cbb commit fe04cb7

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

internal/postgres/insert_module.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ func (db *DB) InsertModule(ctx context.Context, m *internal.Module, lmv *interna
6161
return db.saveModule(ctx, m, lmv)
6262
}
6363

64+
// TODO: Convert this to a txt file and investigate ahead of line blocking root cause.
65+
// If a module is removed from this list, consider backfilling the symbols for all
66+
// existing versions of that module.
67+
var skipSymbols = map[string]bool{
68+
"github.com/citusdata/azure-sdk-for-go": true,
69+
"github.com/seveas/azure-sdk-for-go": true,
70+
"github.com/cdktf/cdktf-provider-azurerm-go/azurerm/v14": true,
71+
"github.com/gardener/gardener": true,
72+
"github.com/gyliu513/okd-origin": true,
73+
"github.com/tombuildsstuff/azure-sdk-for-go": true,
74+
}
75+
6476
// saveModule inserts a Module into the database along with its packages,
6577
// imports, and licenses. If any of these rows already exist, the module and
6678
// corresponding will be deleted and reinserted.
@@ -136,8 +148,10 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module, lmv *internal.
136148
return err
137149
}
138150
isLatest = m.Version == latest
139-
if err := insertSymbols(ctx, tx, m.ModulePath, m.Version, isLatest, pathToID, pathToUnitID, pathToDocs); err != nil {
140-
return err
151+
if !skipSymbols[m.ModulePath] {
152+
if err := insertSymbols(ctx, tx, m.ModulePath, m.Version, isLatest, pathToID, pathToUnitID, pathToDocs); err != nil {
153+
return err
154+
}
141155
}
142156
if !isLatest {
143157
return nil

internal/postgres/insert_module_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,62 @@ func TestPathsToInsert(t *testing.T) {
786786
})
787787
}
788788
}
789+
790+
func TestInsertModuleSkipSymbols(t *testing.T) {
791+
t.Parallel()
792+
ctx := context.Background()
793+
794+
checkSymbolsInserted := func(t *testing.T, db *DB, m *internal.Module) bool {
795+
t.Helper()
796+
var count int
797+
err := db.db.QueryRow(ctx, `
798+
SELECT count(*) FROM documentation_symbols ds
799+
INNER JOIN documentation d ON d.id = ds.documentation_id
800+
INNER JOIN units u ON u.id = d.unit_id
801+
INNER JOIN modules mod ON mod.id = u.module_id
802+
WHERE mod.module_path = $1 AND mod.version = $2`,
803+
m.ModulePath, m.Version).Scan(&count)
804+
if err != nil && err != sql.ErrNoRows {
805+
t.Fatalf("error when checking for symbols: %v", err)
806+
}
807+
return count > 0
808+
}
809+
810+
for _, test := range []struct {
811+
name string
812+
modulePath string
813+
wantInserted bool
814+
}{
815+
{
816+
name: "skipped",
817+
modulePath: "github.com/gardener/gardener",
818+
wantInserted: false,
819+
},
820+
{
821+
name: "not skipped",
822+
modulePath: "example.com/test-module",
823+
wantInserted: true,
824+
},
825+
} {
826+
t.Run(test.name, func(t *testing.T) {
827+
testDB, release := acquire(t)
828+
defer release()
829+
830+
m := sample.Module(test.modulePath, "v1.2.3", "pkg")
831+
m.Units[1].Documentation[0].API = []*internal.Symbol{
832+
{
833+
SymbolMeta: internal.SymbolMeta{
834+
Name: "Foo",
835+
Section: internal.SymbolSectionConstants,
836+
Kind: internal.SymbolKindVariable,
837+
},
838+
},
839+
}
840+
MustInsertModule(ctx, t, testDB, m)
841+
842+
if got := checkSymbolsInserted(t, testDB, m); got != test.wantInserted {
843+
t.Errorf("symbols inserted: got %t; want %t", got, test.wantInserted)
844+
}
845+
})
846+
}
847+
}

0 commit comments

Comments
 (0)