Skip to content

Commit 146d528

Browse files
committed
fixes #1406 Trouble with index MongoDB on DialogFlowDAO
fixes #1411 New stats are not display in Analytics
1 parent 4436bdd commit 146d528

File tree

5 files changed

+187
-2
lines changed

5 files changed

+187
-2
lines changed

bot/storage-mongo/src/main/kotlin/DialogFlowMongoDAO.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import org.litote.kmongo.aggregate
9696
import org.litote.kmongo.all
9797
import org.litote.kmongo.and
9898
import org.litote.kmongo.dateToString
99+
import org.litote.kmongo.deleteMany
99100
import org.litote.kmongo.document
100101
import org.litote.kmongo.eq
101102
import org.litote.kmongo.find
@@ -115,6 +116,7 @@ import org.litote.kmongo.match
115116
import org.litote.kmongo.ne
116117
import org.litote.kmongo.project
117118
import org.litote.kmongo.projection
119+
import org.litote.kmongo.save
118120
import org.litote.kmongo.set
119121
import org.litote.kmongo.setTo
120122
import org.litote.kmongo.size
@@ -174,6 +176,7 @@ internal object DialogFlowMongoDAO : DialogFlowDAO {
174176
ConnectorType,
175177
ActionType,
176178
HourOfDay,
179+
indexOptions = IndexOptions().name("index")
177180
)
178181
} catch (e: Exception) {
179182
logger.error(e)
@@ -207,13 +210,24 @@ internal object DialogFlowMongoDAO : DialogFlowDAO {
207210
}
208211
}
209212

213+
private const val defaultConfKey = "default"
210214

211-
private const val currentProcessedLevel = 1
215+
private val currentProcessedLevelCol =
216+
MongoBotConfiguration.database.getCollection<DialogFlowConfiguration>("flow_configuration")
217+
218+
internal const val currentProcessedLevel = 1
212219

213220
private val crawlStats: Boolean = booleanProperty("tock_dialog_flow_crawl_stats", true)
214221

215222
override fun initFlowStatCrawl() {
216223
if (crawlStats) {
224+
val conf = currentProcessedLevelCol.findOneById(defaultConfKey)
225+
if(conf?.currentProcessedLevel != currentProcessedLevel) {
226+
flowTransitionStatsDateAggregationCol.deleteMany()
227+
flowTransitionStatsDialogAggregationCol.deleteMany()
228+
flowTransitionStatsUserAggregationCol.deleteMany()
229+
currentProcessedLevelCol.save(DialogFlowConfiguration(defaultConfKey, currentProcessedLevel))
230+
}
217231
val executor = Executors.newSingleThreadExecutor()
218232
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(
219233
{

bot/storage-mongo/src/main/kotlin/DialogFlowStateCol.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal data class DialogFlowStateTransitionStatCol(
7171
val text: String?,
7272
val locale: Locale? = null,
7373
val date: Instant = now(),
74-
val processedLevel: Int = 1,
74+
val processedLevel: Int = DialogFlowMongoDAO.currentProcessedLevel,
7575
)
7676

7777
@Data(internal = true)
@@ -130,3 +130,10 @@ internal data class DialogFlowAggregateApplicationIdResult(
130130
val date: LocalDateTime,
131131
val count: Int = 0,
132132
)
133+
134+
@Data(internal = true)
135+
@JacksonData(internal = true)
136+
internal data class DialogFlowConfiguration(
137+
val _id : String,
138+
val currentProcessedLevel: Int = DialogFlowMongoDAO.currentProcessedLevel
139+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ai.tock.bot.mongo
2+
3+
import kotlin.Int
4+
import kotlin.String
5+
import kotlin.Suppress
6+
import kotlin.collections.Collection
7+
import kotlin.collections.Map
8+
import kotlin.reflect.KProperty1
9+
import org.litote.kmongo.property.KCollectionPropertyPath
10+
import org.litote.kmongo.property.KMapPropertyPath
11+
import org.litote.kmongo.property.KPropertyPath
12+
13+
private val ___id: KProperty1<DialogFlowConfiguration, String?>
14+
get() = DialogFlowConfiguration::_id
15+
private val __CurrentProcessedLevel: KProperty1<DialogFlowConfiguration, Int?>
16+
get() = DialogFlowConfiguration::currentProcessedLevel
17+
internal class DialogFlowConfiguration_<T>(previous: KPropertyPath<T, *>?, property: KProperty1<*,
18+
DialogFlowConfiguration?>) : KPropertyPath<T, DialogFlowConfiguration?>(previous,property) {
19+
val _id: KPropertyPath<T, String?>
20+
get() = KPropertyPath(this,___id)
21+
22+
val currentProcessedLevel: KPropertyPath<T, Int?>
23+
get() = KPropertyPath(this,__CurrentProcessedLevel)
24+
25+
companion object {
26+
val _id: KProperty1<DialogFlowConfiguration, String?>
27+
get() = ___id
28+
val CurrentProcessedLevel: KProperty1<DialogFlowConfiguration, Int?>
29+
get() = __CurrentProcessedLevel}
30+
}
31+
32+
internal class DialogFlowConfiguration_Col<T>(previous: KPropertyPath<T, *>?, property:
33+
KProperty1<*, Collection<DialogFlowConfiguration>?>) : KCollectionPropertyPath<T,
34+
DialogFlowConfiguration?, DialogFlowConfiguration_<T>>(previous,property) {
35+
val _id: KPropertyPath<T, String?>
36+
get() = KPropertyPath(this,___id)
37+
38+
val currentProcessedLevel: KPropertyPath<T, Int?>
39+
get() = KPropertyPath(this,__CurrentProcessedLevel)
40+
41+
@Suppress("UNCHECKED_CAST")
42+
override fun memberWithAdditionalPath(additionalPath: String): DialogFlowConfiguration_<T> =
43+
DialogFlowConfiguration_(this, customProperty(this, additionalPath))}
44+
45+
internal class DialogFlowConfiguration_Map<T, K>(previous: KPropertyPath<T, *>?, property:
46+
KProperty1<*, Map<K, DialogFlowConfiguration>?>) : KMapPropertyPath<T, K,
47+
DialogFlowConfiguration?, DialogFlowConfiguration_<T>>(previous,property) {
48+
val _id: KPropertyPath<T, String?>
49+
get() = KPropertyPath(this,___id)
50+
51+
val currentProcessedLevel: KPropertyPath<T, Int?>
52+
get() = KPropertyPath(this,__CurrentProcessedLevel)
53+
54+
@Suppress("UNCHECKED_CAST")
55+
override fun memberWithAdditionalPath(additionalPath: String): DialogFlowConfiguration_<T> =
56+
DialogFlowConfiguration_(this, customProperty(this, additionalPath))}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package ai.tock.bot.mongo
2+
3+
import com.fasterxml.jackson.core.JsonParser
4+
import com.fasterxml.jackson.core.JsonToken
5+
import com.fasterxml.jackson.databind.DeserializationContext
6+
import com.fasterxml.jackson.databind.JsonDeserializer
7+
import com.fasterxml.jackson.databind.module.SimpleModule
8+
import kotlin.Int
9+
import kotlin.String
10+
import kotlin.collections.Map
11+
import kotlin.reflect.KFunction
12+
import kotlin.reflect.KParameter
13+
import kotlin.reflect.full.findParameterByName
14+
import kotlin.reflect.full.primaryConstructor
15+
import org.litote.jackson.JacksonModuleServiceLoader
16+
17+
internal class DialogFlowConfiguration_Deserializer : JsonDeserializer<DialogFlowConfiguration>(),
18+
JacksonModuleServiceLoader {
19+
override fun module() = SimpleModule().addDeserializer(DialogFlowConfiguration::class.java,
20+
this)
21+
22+
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): DialogFlowConfiguration {
23+
with(p) {
24+
var __id_: String? = null
25+
var __id_set : Boolean = false
26+
var _currentProcessedLevel_: Int? = null
27+
var _currentProcessedLevel_set : Boolean = false
28+
var _token_ : JsonToken? = currentToken
29+
while (_token_?.isStructEnd != true) {
30+
if(_token_ != JsonToken.FIELD_NAME) {
31+
_token_ = nextToken()
32+
if (_token_?.isStructEnd == true) break
33+
}
34+
35+
val _fieldName_ = currentName
36+
_token_ = nextToken()
37+
when (_fieldName_) {
38+
"_id" -> {
39+
__id_ = if(_token_ == JsonToken.VALUE_NULL) null
40+
else p.text;
41+
__id_set = true
42+
}
43+
"currentProcessedLevel" -> {
44+
_currentProcessedLevel_ = if(_token_ == JsonToken.VALUE_NULL) null
45+
else p.intValue;
46+
_currentProcessedLevel_set = true
47+
}
48+
else -> {
49+
if (_token_?.isStructStart == true)
50+
p.skipChildren()
51+
nextToken()
52+
}
53+
}
54+
_token_ = currentToken
55+
}
56+
return if(__id_set && _currentProcessedLevel_set)
57+
DialogFlowConfiguration(_id = __id_!!, currentProcessedLevel =
58+
_currentProcessedLevel_!!)
59+
else {
60+
val map = mutableMapOf<KParameter, Any?>()
61+
if(__id_set)
62+
map[parameters.getValue("_id")] = __id_
63+
if(_currentProcessedLevel_set)
64+
map[parameters.getValue("currentProcessedLevel")] = _currentProcessedLevel_
65+
primaryConstructor.callBy(map)
66+
}
67+
}
68+
}
69+
70+
companion object {
71+
private val primaryConstructor: KFunction<DialogFlowConfiguration> by
72+
lazy(LazyThreadSafetyMode.PUBLICATION) {
73+
DialogFlowConfiguration::class.primaryConstructor!! }
74+
75+
private val parameters: Map<String, KParameter> by lazy(LazyThreadSafetyMode.PUBLICATION) {
76+
kotlin.collections.mapOf("_id" to primaryConstructor.findParameterByName("_id")!!,
77+
"currentProcessedLevel" to
78+
primaryConstructor.findParameterByName("currentProcessedLevel")!!) }
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ai.tock.bot.mongo
2+
3+
import com.fasterxml.jackson.core.JsonGenerator
4+
import com.fasterxml.jackson.databind.SerializerProvider
5+
import com.fasterxml.jackson.databind.module.SimpleModule
6+
import com.fasterxml.jackson.databind.ser.std.StdSerializer
7+
import org.litote.jackson.JacksonModuleServiceLoader
8+
9+
internal class DialogFlowConfiguration_Serializer :
10+
StdSerializer<DialogFlowConfiguration>(DialogFlowConfiguration::class.java),
11+
JacksonModuleServiceLoader {
12+
override fun module() = SimpleModule().addSerializer(DialogFlowConfiguration::class.java, this)
13+
14+
override fun serialize(
15+
value: DialogFlowConfiguration,
16+
gen: JsonGenerator,
17+
serializers: SerializerProvider
18+
) {
19+
gen.writeStartObject()
20+
gen.writeFieldName("_id")
21+
val __id_ = value._id
22+
gen.writeString(__id_)
23+
gen.writeFieldName("currentProcessedLevel")
24+
val _currentProcessedLevel_ = value.currentProcessedLevel
25+
gen.writeNumber(_currentProcessedLevel_)
26+
gen.writeEndObject()
27+
}
28+
}

0 commit comments

Comments
 (0)