@@ -42,13 +42,14 @@ import io.iohk.atala.prism.node.services.models.AtalaObjectNotification
42
42
import io .iohk .atala .prism .node .utils .syntax .DBConnectionOps
43
43
import io .iohk .atala .prism .protos .node_models
44
44
import io .iohk .atala .prism .protos .node_models .SignedAtalaOperation
45
+ import org .slf4j .LoggerFactory
45
46
import tofu .higherKind .Mid
46
47
import tofu .logging .Logs
47
48
import tofu .logging .ServiceLogging
48
49
import tofu .logging .derivation .loggable
49
50
import tofu .syntax .feither ._
50
51
import tofu .syntax .monadic ._
51
- import org . slf4j . LoggerFactory
52
+
52
53
import java .time .Instant
53
54
54
55
@ derive(applyK)
@@ -98,98 +99,6 @@ private final class ObjectManagementServiceImpl[F[_]: MonadCancelThrow](
98
99
) extends ObjectManagementService [F ] {
99
100
private val logger = LoggerFactory .getLogger(getClass)
100
101
101
- def saveObjects2 (
102
- notifications : List [AtalaObjectNotification ]
103
- ): F [Either [SaveObjectError , Boolean ]] = {
104
- if (notifications.isEmpty) {
105
- true .asRight[SaveObjectError ].pure[F ]
106
- } else {
107
-
108
- def applyTransactions (atalaObjectInfos : List [AtalaObjectInfo ]): F [Either [SaveObjectError , Boolean ]] = {
109
- for {
110
- // Process all objects and apply them to the state
111
- transactions <- atalaObjectInfos.traverse { case (obj) =>
112
- Monad [F ].pure(processObject(obj))
113
- }
114
- result <- transactions.sequence.flatTraverse { txs =>
115
- txs
116
- .traverse(_.logSQLErrorsV2(" Transaction saving objects" ).attemptSql)
117
- .transact(xa)
118
- .map(_.sequence)
119
- .map(_.map(_ => true ))
120
- .leftMapIn(err => SaveObjectError (err.getMessage))
121
- }
122
-
123
- } yield result
124
- }
125
-
126
- def processObjectList (
127
- notifications : List [AtalaObjectNotification ]
128
- ): F [Either [SaveObjectError , Boolean ]] = {
129
- val pairedInserts : List [
130
- (AtalaObjectId , AtalaObjectsDAO .AtalaObjectCreateData , AtalaObjectsDAO .AtalaObjectSetTransactionInfo )
131
- ] =
132
- notifications.map { notification =>
133
- val objectBytes = notification.atalaObject.toByteArray
134
- val objId = AtalaObjectId .of(objectBytes)
135
- (
136
- objId,
137
- AtalaObjectsDAO .AtalaObjectCreateData (
138
- objId,
139
- objectBytes,
140
- AtalaObjectStatus .Processed
141
- ),
142
- AtalaObjectsDAO .AtalaObjectSetTransactionInfo (
143
- objId,
144
- notification.transaction
145
- )
146
- )
147
- }
148
-
149
- val (objectIds, objectInserts, transactionInserts) = pairedInserts.unzip3
150
-
151
- // Bulk database operations
152
- val bulkQuery = for {
153
- count1 <- AtalaObjectsDAO .insertMany(objectInserts)
154
- count2 <- AtalaObjectsDAO .setManyTransactionInfo(transactionInserts)
155
- count3 <- AtalaObjectTransactionSubmissionsDAO
156
- .updateStatusBatch(
157
- transactionInserts.map(d =>
158
- (
159
- d.transactionInfo.ledger,
160
- d.transactionInfo.transactionId,
161
- AtalaObjectTransactionSubmissionStatus .InLedger
162
- )
163
- )
164
- )
165
- atalaObjectsInfo <- AtalaObjectsDAO .getAtalaObjectsInfo(objectIds)
166
- } yield (count1, count2, count3, atalaObjectsInfo)
167
-
168
- bulkQuery
169
- .logSQLErrorsV2(" bulk processing atala objects" )
170
- .attemptSql
171
- .transact(xa)
172
- .flatMap {
173
- case Left (err) => SaveObjectError (err.getMessage).asLeft[Boolean ].pure[F ]
174
- case Right ((count1, count2, count3, atalaObjectsInfo)) =>
175
- if (
176
- count1 != objectInserts.size || count2 != transactionInserts.size || count3 != transactionInserts.size
177
- ) {
178
- logger.info(
179
- s " Count mismatches: Create(exp= ${objectInserts.size},got= $count1), " +
180
- s " TxInfo(exp= ${transactionInserts.size},got= $count2), " +
181
- s " Status(exp= ${transactionInserts.size},got= $count3) "
182
- )
183
- }
184
- // Apply transactions to the state finally this sequencial operation similar to applyTransaction
185
- applyTransactions(atalaObjectsInfo)
186
- }
187
- }
188
-
189
- processObjectList(notifications)
190
- }
191
- }
192
-
193
102
def saveObjects (
194
103
notifications : List [AtalaObjectNotification ]
195
104
): F [Either [SaveObjectError , Boolean ]] = {
@@ -262,7 +171,7 @@ private final class ObjectManagementServiceImpl[F[_]: MonadCancelThrow](
262
171
if (
263
172
count1 != objectInserts.size || count2 != transactionInserts.size || count3 != transactionInserts.size
264
173
) {
265
- println (
174
+ logger.info (
266
175
s " Count mismatches: Create(exp= ${objectInserts.size},got= $count1), " +
267
176
s " TxInfo(exp= ${transactionInserts.size},got= $count2), " +
268
177
s " Status(exp= ${transactionInserts.size},got= $count3) "
0 commit comments