Add has_been_merged to DB

This commit is contained in:
Andras Schmelczer 2025-10-19 11:47:55 +01:00
commit 12aa457e3a
6 changed files with 28 additions and 6 deletions

View file

@ -278,7 +278,8 @@ impl Database {
content, content,
is_deleted, is_deleted,
user_id, user_id,
device_id device_id,
has_been_merged
from latest_document_versions from latest_document_versions
where relative_path = ? where relative_path = ?
order by vault_update_id desc -- `latest_document_versions` only contains a single latest version of each document, however, order by vault_update_id desc -- `latest_document_versions` only contains a single latest version of each document, however,
@ -317,7 +318,8 @@ impl Database {
content, content,
is_deleted, is_deleted,
user_id, user_id,
device_id device_id,
has_been_merged
from latest_document_versions from latest_document_versions
where document_id = ? where document_id = ?
"#, "#,
@ -351,7 +353,8 @@ impl Database {
content, content,
is_deleted, is_deleted,
user_id, user_id,
device_id device_id,
has_been_merged
from documents from documents
where vault_update_id = ?"#, where vault_update_id = ?"#,
vault_update_id vault_update_id

View file

@ -0,0 +1,13 @@
ALTER TABLE documents ADD COLUMN has_been_merged BOOLEAN NOT NULL DEFAULT False;
DROP VIEW latest_document_versions;
CREATE VIEW IF NOT EXISTS latest_document_versions AS --recreate view as it now includes one more field
SELECT d.*
FROM documents d
INNER JOIN (
SELECT MAX(vault_update_id) AS max_version_id
FROM documents
GROUP BY document_id
) max_versions
ON d.vault_update_id = max_versions.max_version_id;

View file

@ -20,6 +20,8 @@ pub struct StoredDocumentVersion {
pub is_deleted: bool, pub is_deleted: bool,
pub user_id: UserId, pub user_id: UserId,
pub device_id: DeviceId, pub device_id: DeviceId,
#[allow(dead_code)] // This is for manual analysis
pub has_been_merged: bool,
} }
impl PartialEq<Self> for StoredDocumentVersion { impl PartialEq<Self> for StoredDocumentVersion {

View file

@ -77,6 +77,7 @@ pub async fn create_document(
is_deleted: false, is_deleted: false,
user_id: user.name, user_id: user.name,
device_id: device_id.0, device_id: device_id.0,
has_been_merged: false,
}; };
state state

View file

@ -66,6 +66,7 @@ pub async fn delete_document(
is_deleted: true, is_deleted: true,
user_id: user.name, user_id: user.name,
device_id: device_id.0, device_id: device_id.0,
has_been_merged: false
}; };
state state

View file

@ -120,11 +120,12 @@ pub async fn update_document(
))); )));
} }
let merged_content = if is_file_type_mergable(&sanitized_relative_path) let are_all_participants_mergable = is_file_type_mergable(&sanitized_relative_path)
&& !is_binary(&parent_document.content) && !is_binary(&parent_document.content)
&& !is_binary(&latest_version.content) && !is_binary(&latest_version.content)
&& !is_binary(&content) && !is_binary(&content);
{
let merged_content = if are_all_participants_mergable {
reconcile( reconcile(
str::from_utf8(&parent_document.content) str::from_utf8(&parent_document.content)
.expect("parent must be valid UTF-8 because it's not binary"), .expect("parent must be valid UTF-8 because it's not binary"),
@ -177,6 +178,7 @@ pub async fn update_document(
is_deleted: false, is_deleted: false,
user_id: user.name, user_id: user.name,
device_id: device_id.0, device_id: device_id.0,
has_been_merged: are_all_participants_mergable && is_different_from_request_content,
}; };
state state