mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Allow blog posts to be loaded within one transaction
This commit is contained in:
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -98,6 +99,11 @@ public interface BlogManager {
|
|||||||
*/
|
*/
|
||||||
Collection<Blog> getBlogs() throws DbException;
|
Collection<Blog> getBlogs() throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the group IDs of all blogs to which the user subscribes.
|
||||||
|
*/
|
||||||
|
Collection<GroupId> getBlogIds(Transaction txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the header of the blog post with the given ID.
|
* Returns the header of the blog post with the given ID.
|
||||||
*/
|
*/
|
||||||
@@ -108,11 +114,22 @@ public interface BlogManager {
|
|||||||
*/
|
*/
|
||||||
String getPostText(MessageId m) throws DbException;
|
String getPostText(MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the text of the blog post with the given ID.
|
||||||
|
*/
|
||||||
|
String getPostText(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the headers of all posts in the given blog.
|
* Returns the headers of all posts in the given blog.
|
||||||
*/
|
*/
|
||||||
Collection<BlogPostHeader> getPostHeaders(GroupId g) throws DbException;
|
Collection<BlogPostHeader> getPostHeaders(GroupId g) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the headers of all posts in the given blog.
|
||||||
|
*/
|
||||||
|
List<BlogPostHeader> getPostHeaders(Transaction txn, GroupId g)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a blog post as read or unread.
|
* Marks a blog post as read or unread.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -445,6 +445,14 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<GroupId> getBlogIds(Transaction txn) throws DbException {
|
||||||
|
List<GroupId> groupIds = new ArrayList<>();
|
||||||
|
Collection<Group> groups = db.getGroups(txn, CLIENT_ID, MAJOR_VERSION);
|
||||||
|
for (Group g : groups) groupIds.add(g.getId());
|
||||||
|
return groupIds;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlogPostHeader getPostHeader(GroupId g, MessageId m)
|
public BlogPostHeader getPostHeader(GroupId g, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -471,6 +479,15 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPostText(Transaction txn, MessageId m) throws DbException {
|
||||||
|
try {
|
||||||
|
return getPostText(clientHelper.getMessageAsList(txn, m));
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getPostText(BdfList message) throws FormatException {
|
private String getPostText(BdfList message) throws FormatException {
|
||||||
MessageType type = MessageType.valueOf(message.getLong(0).intValue());
|
MessageType type = MessageType.valueOf(message.getLong(0).intValue());
|
||||||
if (type == POST) {
|
if (type == POST) {
|
||||||
@@ -488,7 +505,12 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
@Override
|
@Override
|
||||||
public Collection<BlogPostHeader> getPostHeaders(GroupId g)
|
public Collection<BlogPostHeader> getPostHeaders(GroupId g)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
return db.transactionWithResult(true, txn -> getPostHeaders(txn, g));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlogPostHeader> getPostHeaders(Transaction txn, GroupId g)
|
||||||
|
throws DbException {
|
||||||
// Query for posts and comments only
|
// Query for posts and comments only
|
||||||
BdfDictionary query1 = BdfDictionary.of(
|
BdfDictionary query1 = BdfDictionary.of(
|
||||||
new BdfEntry(KEY_TYPE, POST.getInt())
|
new BdfEntry(KEY_TYPE, POST.getInt())
|
||||||
@@ -497,8 +519,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
new BdfEntry(KEY_TYPE, COMMENT.getInt())
|
new BdfEntry(KEY_TYPE, COMMENT.getInt())
|
||||||
);
|
);
|
||||||
|
|
||||||
Collection<BlogPostHeader> headers = new ArrayList<>();
|
List<BlogPostHeader> headers = new ArrayList<>();
|
||||||
Transaction txn = db.startTransaction(true);
|
|
||||||
try {
|
try {
|
||||||
Map<MessageId, BdfDictionary> metadata1 =
|
Map<MessageId, BdfDictionary> metadata1 =
|
||||||
clientHelper.getMessageMetadataAsDictionary(txn, g, query1);
|
clientHelper.getMessageMetadataAsDictionary(txn, g, query1);
|
||||||
@@ -528,13 +549,10 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
entry.getKey(), meta, authorInfos);
|
entry.getKey(), meta, authorInfos);
|
||||||
headers.add(h);
|
headers.add(h);
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
|
||||||
return headers;
|
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
}
|
||||||
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user