forked from ALHP/ALHP.GO
Hash each PKGBUILD and compare before parsing, fixes #25
This will speed things up significantly. See #25 for more information and discussion.
This commit is contained in:
@@ -39,6 +39,8 @@ type DbPackage struct {
|
||||
BuildDuration uint64 `json:"build_duration,omitempty"`
|
||||
// Updated holds the value of the "updated" field.
|
||||
Updated time.Time `json:"updated,omitempty"`
|
||||
// Hash holds the value of the "hash" field.
|
||||
Hash string `json:"hash,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
@@ -50,7 +52,7 @@ func (*DbPackage) scanValues(columns []string) ([]interface{}, error) {
|
||||
values[i] = new([]byte)
|
||||
case dbpackage.FieldID, dbpackage.FieldStatus, dbpackage.FieldBuildDuration:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case dbpackage.FieldPkgbase, dbpackage.FieldSkipReason, dbpackage.FieldRepository, dbpackage.FieldMarch, dbpackage.FieldVersion, dbpackage.FieldRepoVersion:
|
||||
case dbpackage.FieldPkgbase, dbpackage.FieldSkipReason, dbpackage.FieldRepository, dbpackage.FieldMarch, dbpackage.FieldVersion, dbpackage.FieldRepoVersion, dbpackage.FieldHash:
|
||||
values[i] = new(sql.NullString)
|
||||
case dbpackage.FieldBuildTime, dbpackage.FieldUpdated:
|
||||
values[i] = new(sql.NullTime)
|
||||
@@ -144,6 +146,12 @@ func (dp *DbPackage) assignValues(columns []string, values []interface{}) error
|
||||
} else if value.Valid {
|
||||
dp.Updated = value.Time
|
||||
}
|
||||
case dbpackage.FieldHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hash", values[i])
|
||||
} else if value.Valid {
|
||||
dp.Hash = value.String
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -194,6 +202,8 @@ func (dp *DbPackage) String() string {
|
||||
builder.WriteString(fmt.Sprintf("%v", dp.BuildDuration))
|
||||
builder.WriteString(", updated=")
|
||||
builder.WriteString(dp.Updated.Format(time.ANSIC))
|
||||
builder.WriteString(", hash=")
|
||||
builder.WriteString(dp.Hash)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ const (
|
||||
FieldBuildDuration = "build_duration"
|
||||
// FieldUpdated holds the string denoting the updated field in the database.
|
||||
FieldUpdated = "updated"
|
||||
// FieldHash holds the string denoting the hash field in the database.
|
||||
FieldHash = "hash"
|
||||
// Table holds the table name of the dbpackage in the database.
|
||||
Table = "db_packages"
|
||||
)
|
||||
@@ -47,6 +49,7 @@ var Columns = []string{
|
||||
FieldBuildTime,
|
||||
FieldBuildDuration,
|
||||
FieldUpdated,
|
||||
FieldHash,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
|
@@ -162,6 +162,13 @@ func Updated(v time.Time) predicate.DbPackage {
|
||||
})
|
||||
}
|
||||
|
||||
// Hash applies equality check predicate on the "hash" field. It's identical to HashEQ.
|
||||
func Hash(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PkgbaseEQ applies the EQ predicate on the "pkgbase" field.
|
||||
func PkgbaseEQ(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
@@ -1230,6 +1237,131 @@ func UpdatedNotNil() predicate.DbPackage {
|
||||
})
|
||||
}
|
||||
|
||||
// HashEQ applies the EQ predicate on the "hash" field.
|
||||
func HashEQ(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashNEQ applies the NEQ predicate on the "hash" field.
|
||||
func HashNEQ(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashIn applies the In predicate on the "hash" field.
|
||||
func HashIn(vs ...string) predicate.DbPackage {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldHash), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// HashNotIn applies the NotIn predicate on the "hash" field.
|
||||
func HashNotIn(vs ...string) predicate.DbPackage {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldHash), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// HashGT applies the GT predicate on the "hash" field.
|
||||
func HashGT(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashGTE applies the GTE predicate on the "hash" field.
|
||||
func HashGTE(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashLT applies the LT predicate on the "hash" field.
|
||||
func HashLT(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashLTE applies the LTE predicate on the "hash" field.
|
||||
func HashLTE(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashContains applies the Contains predicate on the "hash" field.
|
||||
func HashContains(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashHasPrefix applies the HasPrefix predicate on the "hash" field.
|
||||
func HashHasPrefix(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashHasSuffix applies the HasSuffix predicate on the "hash" field.
|
||||
func HashHasSuffix(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashIsNil applies the IsNil predicate on the "hash" field.
|
||||
func HashIsNil() predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldHash)))
|
||||
})
|
||||
}
|
||||
|
||||
// HashNotNil applies the NotNil predicate on the "hash" field.
|
||||
func HashNotNil() predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldHash)))
|
||||
})
|
||||
}
|
||||
|
||||
// HashEqualFold applies the EqualFold predicate on the "hash" field.
|
||||
func HashEqualFold(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HashContainsFold applies the ContainsFold predicate on the "hash" field.
|
||||
func HashContainsFold(v string) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldHash), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.DbPackage) predicate.DbPackage {
|
||||
return predicate.DbPackage(func(s *sql.Selector) {
|
||||
|
@@ -142,6 +142,20 @@ func (dpc *DbPackageCreate) SetNillableUpdated(t *time.Time) *DbPackageCreate {
|
||||
return dpc
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (dpc *DbPackageCreate) SetHash(s string) *DbPackageCreate {
|
||||
dpc.mutation.SetHash(s)
|
||||
return dpc
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (dpc *DbPackageCreate) SetNillableHash(s *string) *DbPackageCreate {
|
||||
if s != nil {
|
||||
dpc.SetHash(*s)
|
||||
}
|
||||
return dpc
|
||||
}
|
||||
|
||||
// Mutation returns the DbPackageMutation object of the builder.
|
||||
func (dpc *DbPackageCreate) Mutation() *DbPackageMutation {
|
||||
return dpc.mutation
|
||||
@@ -354,6 +368,14 @@ func (dpc *DbPackageCreate) createSpec() (*DbPackage, *sqlgraph.CreateSpec) {
|
||||
})
|
||||
_node.Updated = value
|
||||
}
|
||||
if value, ok := dpc.mutation.Hash(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: dbpackage.FieldHash,
|
||||
})
|
||||
_node.Hash = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
@@ -199,6 +199,26 @@ func (dpu *DbPackageUpdate) ClearUpdated() *DbPackageUpdate {
|
||||
return dpu
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (dpu *DbPackageUpdate) SetHash(s string) *DbPackageUpdate {
|
||||
dpu.mutation.SetHash(s)
|
||||
return dpu
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (dpu *DbPackageUpdate) SetNillableHash(s *string) *DbPackageUpdate {
|
||||
if s != nil {
|
||||
dpu.SetHash(*s)
|
||||
}
|
||||
return dpu
|
||||
}
|
||||
|
||||
// ClearHash clears the value of the "hash" field.
|
||||
func (dpu *DbPackageUpdate) ClearHash() *DbPackageUpdate {
|
||||
dpu.mutation.ClearHash()
|
||||
return dpu
|
||||
}
|
||||
|
||||
// Mutation returns the DbPackageMutation object of the builder.
|
||||
func (dpu *DbPackageUpdate) Mutation() *DbPackageMutation {
|
||||
return dpu.mutation
|
||||
@@ -430,6 +450,19 @@ func (dpu *DbPackageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
Column: dbpackage.FieldUpdated,
|
||||
})
|
||||
}
|
||||
if value, ok := dpu.mutation.Hash(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: dbpackage.FieldHash,
|
||||
})
|
||||
}
|
||||
if dpu.mutation.HashCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: dbpackage.FieldHash,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, dpu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{dbpackage.Label}
|
||||
@@ -621,6 +654,26 @@ func (dpuo *DbPackageUpdateOne) ClearUpdated() *DbPackageUpdateOne {
|
||||
return dpuo
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (dpuo *DbPackageUpdateOne) SetHash(s string) *DbPackageUpdateOne {
|
||||
dpuo.mutation.SetHash(s)
|
||||
return dpuo
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (dpuo *DbPackageUpdateOne) SetNillableHash(s *string) *DbPackageUpdateOne {
|
||||
if s != nil {
|
||||
dpuo.SetHash(*s)
|
||||
}
|
||||
return dpuo
|
||||
}
|
||||
|
||||
// ClearHash clears the value of the "hash" field.
|
||||
func (dpuo *DbPackageUpdateOne) ClearHash() *DbPackageUpdateOne {
|
||||
dpuo.mutation.ClearHash()
|
||||
return dpuo
|
||||
}
|
||||
|
||||
// Mutation returns the DbPackageMutation object of the builder.
|
||||
func (dpuo *DbPackageUpdateOne) Mutation() *DbPackageMutation {
|
||||
return dpuo.mutation
|
||||
@@ -876,6 +929,19 @@ func (dpuo *DbPackageUpdateOne) sqlSave(ctx context.Context) (_node *DbPackage,
|
||||
Column: dbpackage.FieldUpdated,
|
||||
})
|
||||
}
|
||||
if value, ok := dpuo.mutation.Hash(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: dbpackage.FieldHash,
|
||||
})
|
||||
}
|
||||
if dpuo.mutation.HashCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: dbpackage.FieldHash,
|
||||
})
|
||||
}
|
||||
_node = &DbPackage{config: dpuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
@@ -22,6 +22,7 @@ var (
|
||||
{Name: "build_time", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "build_duration", Type: field.TypeUint64, Nullable: true},
|
||||
{Name: "updated", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "hash", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
// DbPackagesTable holds the schema information for the "db_packages" table.
|
||||
DbPackagesTable = &schema.Table{
|
||||
|
@@ -45,6 +45,7 @@ type DbPackageMutation struct {
|
||||
build_duration *uint64
|
||||
addbuild_duration *uint64
|
||||
updated *time.Time
|
||||
hash *string
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*DbPackage, error)
|
||||
@@ -658,6 +659,55 @@ func (m *DbPackageMutation) ResetUpdated() {
|
||||
delete(m.clearedFields, dbpackage.FieldUpdated)
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (m *DbPackageMutation) SetHash(s string) {
|
||||
m.hash = &s
|
||||
}
|
||||
|
||||
// Hash returns the value of the "hash" field in the mutation.
|
||||
func (m *DbPackageMutation) Hash() (r string, exists bool) {
|
||||
v := m.hash
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldHash returns the old "hash" field's value of the DbPackage entity.
|
||||
// If the DbPackage object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *DbPackageMutation) OldHash(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldHash is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldHash requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldHash: %w", err)
|
||||
}
|
||||
return oldValue.Hash, nil
|
||||
}
|
||||
|
||||
// ClearHash clears the value of the "hash" field.
|
||||
func (m *DbPackageMutation) ClearHash() {
|
||||
m.hash = nil
|
||||
m.clearedFields[dbpackage.FieldHash] = struct{}{}
|
||||
}
|
||||
|
||||
// HashCleared returns if the "hash" field was cleared in this mutation.
|
||||
func (m *DbPackageMutation) HashCleared() bool {
|
||||
_, ok := m.clearedFields[dbpackage.FieldHash]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetHash resets all changes to the "hash" field.
|
||||
func (m *DbPackageMutation) ResetHash() {
|
||||
m.hash = nil
|
||||
delete(m.clearedFields, dbpackage.FieldHash)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *DbPackageMutation) Op() Op {
|
||||
return m.op
|
||||
@@ -672,7 +722,7 @@ func (m *DbPackageMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *DbPackageMutation) Fields() []string {
|
||||
fields := make([]string, 0, 11)
|
||||
fields := make([]string, 0, 12)
|
||||
if m.pkgbase != nil {
|
||||
fields = append(fields, dbpackage.FieldPkgbase)
|
||||
}
|
||||
@@ -706,6 +756,9 @@ func (m *DbPackageMutation) Fields() []string {
|
||||
if m.updated != nil {
|
||||
fields = append(fields, dbpackage.FieldUpdated)
|
||||
}
|
||||
if m.hash != nil {
|
||||
fields = append(fields, dbpackage.FieldHash)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -736,6 +789,8 @@ func (m *DbPackageMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.BuildDuration()
|
||||
case dbpackage.FieldUpdated:
|
||||
return m.Updated()
|
||||
case dbpackage.FieldHash:
|
||||
return m.Hash()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -767,6 +822,8 @@ func (m *DbPackageMutation) OldField(ctx context.Context, name string) (ent.Valu
|
||||
return m.OldBuildDuration(ctx)
|
||||
case dbpackage.FieldUpdated:
|
||||
return m.OldUpdated(ctx)
|
||||
case dbpackage.FieldHash:
|
||||
return m.OldHash(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown DbPackage field %s", name)
|
||||
}
|
||||
@@ -853,6 +910,13 @@ func (m *DbPackageMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetUpdated(v)
|
||||
return nil
|
||||
case dbpackage.FieldHash:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetHash(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown DbPackage field %s", name)
|
||||
}
|
||||
@@ -931,6 +995,9 @@ func (m *DbPackageMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(dbpackage.FieldUpdated) {
|
||||
fields = append(fields, dbpackage.FieldUpdated)
|
||||
}
|
||||
if m.FieldCleared(dbpackage.FieldHash) {
|
||||
fields = append(fields, dbpackage.FieldHash)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -966,6 +1033,9 @@ func (m *DbPackageMutation) ClearField(name string) error {
|
||||
case dbpackage.FieldUpdated:
|
||||
m.ClearUpdated()
|
||||
return nil
|
||||
case dbpackage.FieldHash:
|
||||
m.ClearHash()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown DbPackage nullable field %s", name)
|
||||
}
|
||||
@@ -1007,6 +1077,9 @@ func (m *DbPackageMutation) ResetField(name string) error {
|
||||
case dbpackage.FieldUpdated:
|
||||
m.ResetUpdated()
|
||||
return nil
|
||||
case dbpackage.FieldHash:
|
||||
m.ResetHash()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown DbPackage field %s", name)
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ func (DbPackage) Fields() []ent.Field {
|
||||
field.Time("build_time").Optional(),
|
||||
field.Uint64("build_duration").Positive().Optional(),
|
||||
field.Time("updated").Optional(),
|
||||
field.String("hash").Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user