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

Method writeIndex

app/src/AI/ChatStore.cpp:286–313  ·  view source on GitHub ↗

* @brief Writes m_chats / m_lastActive back to the index file; best effort. */

Source from the content-addressed store, hash-verified

284 * @brief Writes m_chats / m_lastActive back to the index file; best effort.
285 */
286void AI::ChatStore::writeIndex() const
287{
288 QJsonArray arr;
289 for (const auto& meta : m_chats) {
290 QJsonObject obj;
291 obj[QStringLiteral("id")] = meta.id;
292 obj[QStringLiteral("title")] = meta.title;
293 obj[QStringLiteral("createdAt")] = static_cast<double>(meta.createdAt);
294 obj[QStringLiteral("updatedAt")] = static_cast<double>(meta.updatedAt);
295 obj[QStringLiteral("count")] = meta.count;
296 arr.append(obj);
297 }
298
299 QJsonObject root;
300 root[QStringLiteral("schema")] = 1;
301 root[QStringLiteral("lastActive")] = m_lastActive;
302 root[QStringLiteral("chats")] = arr;
303
304 QDir().mkpath(chatsDir());
305 QFile f(indexPath());
306 if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
307 qCWarning(serialStudioAI) << "ChatStore: cannot write index" << f.errorString();
308 return;
309 }
310
311 f.write(QJsonDocument(root).toJson(QJsonDocument::Compact));
312 f.close();
313}

Callers

nothing calls this directly

Calls 6

errorStringMethod · 0.80
appendMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
toJsonMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected