Skip to content

Commit

Permalink
SetMemoryOnly()
Browse files Browse the repository at this point in the history
  • Loading branch information
latolukasz committed Sep 3, 2024
1 parent d3df522 commit d7136bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
15 changes: 6 additions & 9 deletions flusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func (f *flusher) flush(root bool, lazy bool, transaction bool, entities ...Enti

for _, entity := range entities {
initIfNeeded(f.engine.registry, entity)
if entity.getORM().memory {
continue
}
schema := entity.getORM().tableSchema
if !transaction && schema.GetMysql(f.engine).inTransaction {
transaction = true
Expand Down Expand Up @@ -407,9 +410,7 @@ func (f *flusher) executeDeletes(lazy bool) {
if logEvent != nil {
logEvents = append(logEvents, logEvent)
}
if !schema.inMemory {
f.fillLazyQuery(db.GetPoolConfig().GetCode(), deleteSQLPrefix+strconv.FormatUint(id, 10)+")", false, id, logEvents)
}
f.fillLazyQuery(db.GetPoolConfig().GetCode(), deleteSQLPrefix+strconv.FormatUint(id, 10)+")", false, id, logEvents)
}
if hasLocalCache || hasRedis {
cacheKey := schema.getCacheKey(id)
Expand Down Expand Up @@ -489,9 +490,7 @@ func (f *flusher) executeInserts(flushPackage *flushPackage, lazy bool) {
logEvents = append(logEvents, logEvent)
}
}
if !schema.inMemory {
f.fillLazyQuery(db.GetPoolConfig().GetCode(), sql, true, 0, logEvents)
}
f.fillLazyQuery(db.GetPoolConfig().GetCode(), sql, true, 0, logEvents)
} else {
res := db.Exec(sql)
id := res.LastInsertId()
Expand Down Expand Up @@ -611,9 +610,7 @@ func (f *flusher) flushUpdate(entity Entity, bindBuilder *bindBuilder, currentID
if logEvent != nil {
logEvents = append(logEvents, logEvent)
}
if !schema.inMemory {
f.fillLazyQuery(db.GetPoolConfig().GetCode(), sql, false, currentID, logEvents)
}
f.fillLazyQuery(db.GetPoolConfig().GetCode(), sql, false, currentID, logEvents)
} else {
if f.updateSQLs == nil {
f.updateSQLs = make(map[string][]string)
Expand Down
6 changes: 6 additions & 0 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Entity interface {
SetEntityLogMeta(key string, value interface{})
SetField(field string, value interface{}) error
Clone() Entity
SetMemoryOnly(memory bool)
}

type ORM struct {
Expand All @@ -51,6 +52,7 @@ type ORM struct {
elem reflect.Value
idElem reflect.Value
logMeta map[string]interface{}
memory bool
}

func DisableCacheHashCheck() {
Expand Down Expand Up @@ -107,6 +109,10 @@ func (orm *ORM) SetOnDuplicateKeyUpdate(bind Bind) {
orm.onDuplicateKeyUpdate = bind
}

func (orm *ORM) SetMemoryOnly(memory bool) {
orm.memory = memory
}

func (orm *ORM) SetEntityLogMeta(key string, value interface{}) {
if orm.logMeta == nil {
orm.logMeta = make(map[string]interface{})
Expand Down
3 changes: 0 additions & 3 deletions table_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ type tableSchema struct {
logTableName string
skipLogs []string
hasUUID bool
inMemory bool
mapBindToScanPointer mapBindToScanPointer
mapPointerToValue mapPointerToValue
}
Expand Down Expand Up @@ -466,7 +465,6 @@ func (tableSchema *tableSchema) init(registry *Registry, entityType reflect.Type
return fmt.Errorf("entity %s with uuid enabled must be unit64", entityType.String())
}
}
inMemory := tableSchema.getTag("memory", "true", "false") == "true"
uniqueIndices := make(map[string]map[int]string)
uniqueIndicesSimple := make(map[string][]string)
uniqueIndicesSimpleGlobal := make(map[string][]string)
Expand Down Expand Up @@ -575,7 +573,6 @@ func (tableSchema *tableSchema) init(registry *Registry, entityType reflect.Type
tableSchema.uniqueIndicesGlobal = uniqueIndicesSimpleGlobal
tableSchema.hasLog = logPoolName != ""
tableSchema.hasUUID = hasUUID
tableSchema.inMemory = inMemory
tableSchema.logPoolName = logPoolName
tableSchema.logTableName = fmt.Sprintf("_log_%s_%s", tableSchema.mysqlPoolName, tableSchema.tableName)
tableSchema.skipLogs = skipLogs
Expand Down

0 comments on commit d7136bf

Please sign in to comment.