minimized repeated field.GetName calls
This commit is contained in:
		
							parent
							
								
									67e6be8073
								
							
						
					
					
						commit
						6ee25cbe12
					
				| 
						 | 
					@ -504,12 +504,16 @@ func NewRecord(collection *Collection) *Record {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// initialize default field values
 | 
						// initialize default field values
 | 
				
			||||||
 | 
						var fieldName string
 | 
				
			||||||
	for _, field := range collection.Fields {
 | 
						for _, field := range collection.Fields {
 | 
				
			||||||
		if field.GetName() == FieldNameId {
 | 
							fieldName = field.GetName()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if fieldName == FieldNameId {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		value, _ := field.PrepareValue(record, nil)
 | 
							value, _ := field.PrepareValue(record, nil)
 | 
				
			||||||
		record.originalData[field.GetName()] = value
 | 
							record.originalData[fieldName] = value
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return record
 | 
						return record
 | 
				
			||||||
| 
						 | 
					@ -590,8 +594,10 @@ func (m *Record) Fresh() *Record {
 | 
				
			||||||
	newRecord := m.Original()
 | 
						newRecord := m.Original()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// note: this will also load the Id field through m.GetRaw
 | 
						// note: this will also load the Id field through m.GetRaw
 | 
				
			||||||
 | 
						var fieldName string
 | 
				
			||||||
	for _, field := range m.collection.Fields {
 | 
						for _, field := range m.collection.Fields {
 | 
				
			||||||
		newRecord.SetRaw(field.GetName(), m.GetRaw(field.GetName()))
 | 
							fieldName = field.GetName()
 | 
				
			||||||
 | 
							newRecord.SetRaw(fieldName, m.GetRaw(fieldName))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return newRecord
 | 
						return newRecord
 | 
				
			||||||
| 
						 | 
					@ -727,8 +733,10 @@ func (m *Record) MergeExpand(expand map[string]any) {
 | 
				
			||||||
func (m *Record) FieldsData() map[string]any {
 | 
					func (m *Record) FieldsData() map[string]any {
 | 
				
			||||||
	result := make(map[string]any, len(m.collection.Fields))
 | 
						result := make(map[string]any, len(m.collection.Fields))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var fieldName string
 | 
				
			||||||
	for _, field := range m.collection.Fields {
 | 
						for _, field := range m.collection.Fields {
 | 
				
			||||||
		result[field.GetName()] = m.Get(field.GetName())
 | 
							fieldName = field.GetName()
 | 
				
			||||||
 | 
							result[fieldName] = m.Get(fieldName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result
 | 
						return result
 | 
				
			||||||
| 
						 | 
					@ -1062,15 +1070,18 @@ func (m *Record) dbExport() (map[string]any, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := make(map[string]any, len(fields))
 | 
						result := make(map[string]any, len(fields))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var fieldName string
 | 
				
			||||||
	for _, field := range fields {
 | 
						for _, field := range fields {
 | 
				
			||||||
 | 
							fieldName = field.GetName()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if f, ok := field.(DriverValuer); ok {
 | 
							if f, ok := field.(DriverValuer); ok {
 | 
				
			||||||
			v, err := f.DriverValue(m)
 | 
								v, err := f.DriverValue(m)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			result[field.GetName()] = v
 | 
								result[fieldName] = v
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			result[field.GetName()] = m.GetRaw(field.GetName())
 | 
								result[fieldName] = m.GetRaw(fieldName)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1196,8 +1207,11 @@ func (record *Record) PublicExport() map[string]any {
 | 
				
			||||||
	customVisibility := record.customVisibility.GetAll()
 | 
						customVisibility := record.customVisibility.GetAll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// export schema fields
 | 
						// export schema fields
 | 
				
			||||||
 | 
						var fieldName string
 | 
				
			||||||
	for _, f := range record.collection.Fields {
 | 
						for _, f := range record.collection.Fields {
 | 
				
			||||||
		isVisible, hasCustomVisibility = customVisibility[f.GetName()]
 | 
							fieldName = f.GetName()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							isVisible, hasCustomVisibility = customVisibility[fieldName]
 | 
				
			||||||
		if !hasCustomVisibility {
 | 
							if !hasCustomVisibility {
 | 
				
			||||||
			isVisible = !f.GetHidden()
 | 
								isVisible = !f.GetHidden()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -1206,7 +1220,7 @@ func (record *Record) PublicExport() map[string]any {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		export[f.GetName()] = record.Get(f.GetName())
 | 
							export[fieldName] = record.Get(fieldName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// export custom fields
 | 
						// export custom fields
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue