GetReferenceIdToIdWithTransaction Looks up a string reference id and return an internal integer id of an object of type `typeName`
(typeName string, referenceId daptinid.DaptinReferenceId, updateTransaction *sqlx.Tx)
| 3161 | |
| 3162 | // GetReferenceIdToIdWithTransaction Looks up a string reference id and return an internal integer id of an object of type `typeName` |
| 3163 | func GetReferenceIdToIdWithTransaction(typeName string, referenceId daptinid.DaptinReferenceId, updateTransaction *sqlx.Tx) (int64, error) { |
| 3164 | |
| 3165 | cacheKey := fmt.Sprintf("riti-%v-%v", typeName, referenceId) |
| 3166 | |
| 3167 | if OlricCache != nil { |
| 3168 | |
| 3169 | cachedValue, err := OlricCache.Get(context.Background(), cacheKey) |
| 3170 | if err == nil && cachedValue != nil { |
| 3171 | return cachedValue.Int64() |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | var id int64 |
| 3176 | s, q, err := statementbuilder.Squirrel.Select("id"). |
| 3177 | Prepared(true).From(typeName).Where(goqu.Ex{"reference_id": referenceId[:]}).ToSQL() |
| 3178 | if err != nil { |
| 3179 | return 0, err |
| 3180 | } |
| 3181 | stmt, err := updateTransaction.Preparex(s) |
| 3182 | if err != nil { |
| 3183 | log.Errorf("[1666] failed to prepare statment: %v", err) |
| 3184 | return 0, err |
| 3185 | } |
| 3186 | defer func(stmt1 *sqlx.Stmt) { |
| 3187 | err := stmt1.Close() |
| 3188 | if err != nil { |
| 3189 | log.Errorf("failed to close prepared statement: %v", err) |
| 3190 | } |
| 3191 | }(stmt) |
| 3192 | |
| 3193 | err = stmt.QueryRowx(q...).Scan(&id) |
| 3194 | |
| 3195 | if OlricCache != nil && err == nil { |
| 3196 | cachePutErr := OlricCache.Put(context.Background(), cacheKey, id, olric.EX(1*time.Hour), olric.NX()) |
| 3197 | CheckErr(cachePutErr, "failed to cache reference id to id for [%v][%v]", typeName, referenceId) |
| 3198 | } |
| 3199 | |
| 3200 | return id, err |
| 3201 | |
| 3202 | } |
| 3203 | |
| 3204 | // Lookup an string reference id and return a internal integer id of an object of type `typeName` |
| 3205 | func (dbResource *DbResource) GetReferenceIdListToIdList(typeName string, referenceId []string) (map[string]int64, error) { |
no test coverage detected