chore: linting (#15814)
This commit is contained in:
parent
37032fb948
commit
1641bb9f0d
@ -46,9 +46,8 @@ func TestUniqueKeyCodec(t *testing.T) {
|
||||
if isTrivialUniqueKey {
|
||||
assert.ErrorContains(t, err, "no new uniqueness constraint")
|
||||
return
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i))
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// nolint"unused" // ignore unused code linting
|
||||
// nolint:unused // ignore unused code linting
|
||||
package codegen
|
||||
|
||||
import (
|
||||
|
||||
@ -140,9 +140,9 @@ func (t autoIncrementTable) ValidateJSON(reader io.Reader) error {
|
||||
|
||||
if t.customJSONValidator != nil {
|
||||
return t.customJSONValidator(message)
|
||||
} else {
|
||||
return DefaultJSONValidator(message)
|
||||
}
|
||||
|
||||
return DefaultJSONValidator(message)
|
||||
})
|
||||
}
|
||||
|
||||
@ -175,14 +175,14 @@ func (t autoIncrementTable) ImportJSON(ctx context.Context, reader io.Reader) er
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) decodeAutoIncJSON(backend Backend, reader io.Reader, onMsg func(message proto.Message, maxID uint64) error) error {
|
||||
decoder, err := t.startDecodeJson(reader)
|
||||
decoder, err := t.startDecodeJSON(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var seq uint64
|
||||
|
||||
return t.doDecodeJson(decoder,
|
||||
return t.doDecodeJSON(decoder,
|
||||
func(message json.RawMessage) bool {
|
||||
err = json.Unmarshal(message, &seq)
|
||||
if err == nil {
|
||||
|
||||
@ -62,14 +62,15 @@ func flushWrites(store kv.Store, writer *batchStoreWriter) error {
|
||||
|
||||
func flushBuf(store kv.Store, writes []*batchWriterEntry) error {
|
||||
for _, write := range writes {
|
||||
if write.hookCall != nil {
|
||||
switch {
|
||||
case write.hookCall != nil:
|
||||
write.hookCall()
|
||||
} else if !write.delete {
|
||||
case !write.delete:
|
||||
err := store.Set(write.key, write.value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
err := store.Delete(write.key)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -70,7 +70,7 @@ func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) {
|
||||
})
|
||||
}
|
||||
|
||||
func benchInsert(b *testing.B, ctx context.Context) {
|
||||
func benchInsert(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Insert(ctx, &testpb.Balance{
|
||||
@ -81,7 +81,7 @@ func benchInsert(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchUpdate(b *testing.B, ctx context.Context) {
|
||||
func benchUpdate(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Update(ctx, &testpb.Balance{
|
||||
@ -92,7 +92,7 @@ func benchUpdate(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchGet(b *testing.B, ctx context.Context) {
|
||||
func benchGet(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
balance, err := balanceTable.Get(ctx, fmt.Sprintf("acct%d", i), "bar")
|
||||
@ -101,7 +101,7 @@ func benchGet(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchDelete(b *testing.B, ctx context.Context) {
|
||||
func benchDelete(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Delete(ctx, &testpb.Balance{
|
||||
|
||||
@ -16,9 +16,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
primaryKeyId uint32 = 0
|
||||
indexIdLimit uint32 = 32768
|
||||
seqId = indexIdLimit
|
||||
primaryKeyID uint32 = 0
|
||||
indexIDLimit uint32 = 32768
|
||||
seqID = indexIDLimit
|
||||
)
|
||||
|
||||
// Options are options for building a Table.
|
||||
@ -84,8 +84,8 @@ func Build(options Options) (Table, error) {
|
||||
indexes: []Index{},
|
||||
indexesByFields: map[fieldnames.FieldNames]concreteIndex{},
|
||||
uniqueIndexesByFields: map[fieldnames.FieldNames]UniqueIndex{},
|
||||
entryCodecsById: map[uint32]ormkv.EntryCodec{},
|
||||
indexesById: map[uint32]Index{},
|
||||
entryCodecsByID: map[uint32]ormkv.EntryCodec{},
|
||||
indexesByID: map[uint32]Index{},
|
||||
typeResolver: options.TypeResolver,
|
||||
customJSONValidator: options.JSONValidator,
|
||||
}
|
||||
@ -125,22 +125,22 @@ func Build(options Options) (Table, error) {
|
||||
|
||||
pkIndex.PrimaryKeyCodec = pkCodec
|
||||
table.tablePrefix = prefix
|
||||
table.tableId = singletonDesc.Id
|
||||
table.tableID = singletonDesc.Id
|
||||
|
||||
return &singleton{table}, nil
|
||||
default:
|
||||
return nil, ormerrors.NoTableDescriptor.Wrapf("missing table descriptor for %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
tableId := tableDesc.Id
|
||||
if tableId == 0 {
|
||||
tableID := tableDesc.Id
|
||||
if tableID == 0 {
|
||||
return nil, ormerrors.InvalidTableId.Wrapf("table %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
prefix := options.Prefix
|
||||
prefix = encodeutil.AppendVarUInt32(prefix, tableId)
|
||||
prefix = encodeutil.AppendVarUInt32(prefix, tableID)
|
||||
table.tablePrefix = prefix
|
||||
table.tableId = tableId
|
||||
table.tableID = tableID
|
||||
|
||||
if tableDesc.PrimaryKey == nil {
|
||||
return nil, ormerrors.MissingPrimaryKey.Wrap(string(messageDescriptor.FullName()))
|
||||
@ -153,7 +153,7 @@ func Build(options Options) (Table, error) {
|
||||
return nil, ormerrors.InvalidTableDefinition.Wrapf("empty primary key fields for %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
pkPrefix := encodeutil.AppendVarUInt32(prefix, primaryKeyId)
|
||||
pkPrefix := encodeutil.AppendVarUInt32(prefix, primaryKeyID)
|
||||
pkCodec, err := ormkv.NewPrimaryKeyCodec(
|
||||
pkPrefix,
|
||||
options.MessageType,
|
||||
@ -167,17 +167,17 @@ func Build(options Options) (Table, error) {
|
||||
pkIndex.PrimaryKeyCodec = pkCodec
|
||||
table.indexesByFields[pkFields] = pkIndex
|
||||
table.uniqueIndexesByFields[pkFields] = pkIndex
|
||||
table.entryCodecsById[primaryKeyId] = pkIndex
|
||||
table.indexesById[primaryKeyId] = pkIndex
|
||||
table.entryCodecsByID[primaryKeyID] = pkIndex
|
||||
table.indexesByID[primaryKeyID] = pkIndex
|
||||
table.indexes = append(table.indexes, pkIndex)
|
||||
|
||||
for _, idxDesc := range tableDesc.Index {
|
||||
id := idxDesc.Id
|
||||
if id == 0 || id >= indexIdLimit {
|
||||
if id == 0 || id >= indexIDLimit {
|
||||
return nil, ormerrors.InvalidIndexId.Wrapf("index on table %s with fields %s, invalid id %d", messageDescriptor.FullName(), idxDesc.Fields, id)
|
||||
}
|
||||
|
||||
if _, ok := table.entryCodecsById[id]; ok {
|
||||
if _, ok := table.entryCodecsByID[id]; ok {
|
||||
return nil, ormerrors.DuplicateIndexId.Wrapf("id %d on table %s", id, messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
@ -264,8 +264,8 @@ func Build(options Options) (Table, error) {
|
||||
table.indexesByFields[name] = index
|
||||
}
|
||||
|
||||
table.entryCodecsById[id] = index
|
||||
table.indexesById[id] = index
|
||||
table.entryCodecsByID[id] = index
|
||||
table.indexesByID[id] = index
|
||||
table.indexes = append(table.indexes, index)
|
||||
table.indexers = append(table.indexers, index.(indexer))
|
||||
}
|
||||
@ -276,9 +276,9 @@ func Build(options Options) (Table, error) {
|
||||
return nil, ormerrors.InvalidAutoIncrementKey.Wrapf("field %s", autoIncField.FullName())
|
||||
}
|
||||
|
||||
seqPrefix := encodeutil.AppendVarUInt32(prefix, seqId)
|
||||
seqPrefix := encodeutil.AppendVarUInt32(prefix, seqID)
|
||||
seqCodec := ormkv.NewSeqCodec(options.MessageType, seqPrefix)
|
||||
table.entryCodecsById[seqId] = seqCodec
|
||||
table.entryCodecsByID[seqID] = seqCodec
|
||||
return &autoIncrementTable{
|
||||
tableImpl: table,
|
||||
autoIncField: autoIncField,
|
||||
|
||||
@ -120,6 +120,6 @@ func (i indexKeyIndex) readValueFromIndexKey(backend ReadBackend, primaryKey []p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p indexKeyIndex) Fields() string {
|
||||
return p.fields.String()
|
||||
func (i indexKeyIndex) Fields() string {
|
||||
return i.fields.String()
|
||||
}
|
||||
|
||||
@ -37,9 +37,9 @@ func (t singleton) ValidateJSON(reader io.Reader) error {
|
||||
|
||||
if t.customJSONValidator != nil {
|
||||
return t.customJSONValidator(msg)
|
||||
} else {
|
||||
return DefaultJSONValidator(msg)
|
||||
}
|
||||
|
||||
return DefaultJSONValidator(msg)
|
||||
}
|
||||
|
||||
func (t singleton) ImportJSON(ctx context.Context, reader io.Reader) error {
|
||||
|
||||
@ -24,10 +24,10 @@ type tableImpl struct {
|
||||
indexes []Index
|
||||
indexesByFields map[fieldnames.FieldNames]concreteIndex
|
||||
uniqueIndexesByFields map[fieldnames.FieldNames]UniqueIndex
|
||||
indexesById map[uint32]Index
|
||||
entryCodecsById map[uint32]ormkv.EntryCodec
|
||||
indexesByID map[uint32]Index
|
||||
entryCodecsByID map[uint32]ormkv.EntryCodec
|
||||
tablePrefix []byte
|
||||
tableId uint32
|
||||
tableID uint32
|
||||
typeResolver TypeResolver
|
||||
customJSONValidator func(message proto.Message) error
|
||||
}
|
||||
@ -44,7 +44,7 @@ func (t tableImpl) PrimaryKey() UniqueIndex {
|
||||
}
|
||||
|
||||
func (t tableImpl) GetIndexByID(id uint32) Index {
|
||||
return t.indexesById[id]
|
||||
return t.indexesByID[id]
|
||||
}
|
||||
|
||||
func (t tableImpl) Save(ctx context.Context, message proto.Message) error {
|
||||
@ -187,16 +187,16 @@ func (t tableImpl) DefaultJSON() json.RawMessage {
|
||||
return json.RawMessage("[]")
|
||||
}
|
||||
|
||||
func (t tableImpl) decodeJson(reader io.Reader, onMsg func(message proto.Message) error) error {
|
||||
decoder, err := t.startDecodeJson(reader)
|
||||
func (t tableImpl) decodeJSON(reader io.Reader, onMsg func(message proto.Message) error) error {
|
||||
decoder, err := t.startDecodeJSON(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.doDecodeJson(decoder, nil, onMsg)
|
||||
return t.doDecodeJSON(decoder, nil, onMsg)
|
||||
}
|
||||
|
||||
func (t tableImpl) startDecodeJson(reader io.Reader) (*json.Decoder, error) {
|
||||
func (t tableImpl) startDecodeJSON(reader io.Reader) (*json.Decoder, error) {
|
||||
decoder := json.NewDecoder(reader)
|
||||
token, err := decoder.Token()
|
||||
if err != nil {
|
||||
@ -213,7 +213,7 @@ func (t tableImpl) startDecodeJson(reader io.Reader) (*json.Decoder, error) {
|
||||
// onFirst is called on the first RawMessage and used for auto-increment tables
|
||||
// to decode the sequence in which case it should return true.
|
||||
// onMsg is called on every decoded message
|
||||
func (t tableImpl) doDecodeJson(decoder *json.Decoder, onFirst func(message json.RawMessage) bool, onMsg func(message proto.Message) error) error {
|
||||
func (t tableImpl) doDecodeJSON(decoder *json.Decoder, onFirst func(message json.RawMessage) bool, onMsg func(message proto.Message) error) error {
|
||||
unmarshalOptions := protojson.UnmarshalOptions{Resolver: t.typeResolver}
|
||||
|
||||
first := true
|
||||
@ -280,7 +280,7 @@ func DefaultJSONValidator(message proto.Message) error {
|
||||
}
|
||||
|
||||
func (t tableImpl) ValidateJSON(reader io.Reader) error {
|
||||
return t.decodeJson(reader, func(message proto.Message) error {
|
||||
return t.decodeJSON(reader, func(message proto.Message) error {
|
||||
if t.customJSONValidator != nil {
|
||||
return t.customJSONValidator(message)
|
||||
}
|
||||
@ -295,7 +295,7 @@ func (t tableImpl) ImportJSON(ctx context.Context, reader io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.decodeJson(reader, func(message proto.Message) error {
|
||||
return t.decodeJSON(reader, func(message proto.Message) error {
|
||||
return t.save(ctx, backend, message, saveModeDefault)
|
||||
})
|
||||
}
|
||||
@ -366,7 +366,7 @@ func (t tableImpl) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
|
||||
}
|
||||
|
||||
idx, ok := t.entryCodecsById[uint32(id)]
|
||||
idx, ok := t.entryCodecsByID[uint32(id)]
|
||||
if !ok {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find field with id %d", id)
|
||||
}
|
||||
@ -391,7 +391,7 @@ func (t tableImpl) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
|
||||
}
|
||||
|
||||
func (t tableImpl) ID() uint32 {
|
||||
return t.tableId
|
||||
return t.tableID
|
||||
}
|
||||
|
||||
func (t tableImpl) Has(ctx context.Context, message proto.Message) (found bool, err error) {
|
||||
|
||||
@ -797,7 +797,7 @@ func TestJSONExportImport(t *testing.T) {
|
||||
assertTablesEqual(t, table, store, store2)
|
||||
}
|
||||
|
||||
func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) {
|
||||
func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) { //nolint:revive // ignore long function name
|
||||
it, err := table.List(ctx, nil)
|
||||
assert.NilError(t, err)
|
||||
it2, err := table.List(ctx2, nil)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user