MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / readIndex

Method readIndex

app/src/AI/ChatStore.cpp:248–281  ·  view source on GitHub ↗

* @brief Reads the index file into m_chats / m_lastActive; tolerant of a missing file. */

Source from the content-addressed store, hash-verified

246 * @brief Reads the index file into m_chats / m_lastActive; tolerant of a missing file.
247 */
248void AI::ChatStore::readIndex()
249{
250 m_chats.clear();
251 m_lastActive.clear();
252
253 QFile f(indexPath());
254 if (!f.exists() || !f.open(QIODevice::ReadOnly))
255 return;
256
257 const auto bytes = f.readAll();
258 f.close();
259
260 const auto doc = QJsonDocument::fromJson(bytes);
261 if (!doc.isObject())
262 return;
263
264 const auto root = doc.object();
265 m_lastActive = root.value(QStringLiteral("lastActive")).toString();
266
267 const auto arr = root.value(QStringLiteral("chats")).toArray();
268 for (const auto& v : arr) {
269 const auto obj = v.toObject();
270 const auto created = obj.value(QStringLiteral("createdAt"));
271 const auto updated = obj.value(QStringLiteral("updatedAt"));
272 Meta meta;
273 meta.id = obj.value(QStringLiteral("id")).toString();
274 meta.title = obj.value(QStringLiteral("title")).toString();
275 meta.createdAt = static_cast<qint64>(SerialStudio::toDouble(created));
276 meta.updatedAt = static_cast<qint64>(SerialStudio::toDouble(updated));
277 meta.count = obj.value(QStringLiteral("count")).toInt();
278 if (!meta.id.isEmpty())
279 m_chats.append(meta);
280 }
281}
282
283/**
284 * @brief Writes m_chats / m_lastActive back to the index file; best effort.

Callers

nothing calls this directly

Calls 8

fromJsonFunction · 0.85
existsMethod · 0.80
isEmptyMethod · 0.80
clearMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
valueMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected