diff --git a/src/Cache.cpp b/src/Cache.cpp
index a518188093623a96193de6b0c031f4c66d048e8e..98fe64c007a8d1a04e72f4a2378d0712935f4d6e 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -1031,7 +1031,7 @@ Cache::saveState(const mtx::responses::Sync &res)
                 updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
 
                 // Process the account_data associated with this room
-                if (!res.account_data.events.empty()) {
+                if (!room.second.account_data.events.empty()) {
                         auto accountDataDb = getAccountDataDb(txn, room.first);
 
                         bool has_new_tags = false;