Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mathieu Féry
M1Alma WebAndCloud Server
Commits
02faec66
Unverified
Commit
02faec66
authored
Dec 05, 2021
by
Féry Mathieu (Mathius)
Browse files
feat(db): Reduce call of datastore with getAllWithoutLinks
parent
ebfbd6e9
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/univnantes/webandcloud/api/controllers/v1/Posts.java
View file @
02faec66
...
...
@@ -53,7 +53,7 @@ public class Posts extends BaseController {
public
WithCursor
<
List
<
Post
>>
posts
(
@Parameter
(
description
=
"Limit for request"
,
example
=
"2"
)
@RequestParam
@Nullable
Integer
limit
,
@Parameter
(
description
=
"Cursor for next entity"
,
example
=
"CgA="
)
@RequestParam
@Nullable
String
cursor
)
{
return
postDB
.
getAllCreatedDesc
(
limit
,
cursor
!=
null
?
Cursor
.
fromUrlSafe
(
cursor
)
:
null
);
return
postDB
.
getAllCreatedDesc
WithoutLinks
(
limit
,
cursor
!=
null
?
Cursor
.
fromUrlSafe
(
cursor
)
:
null
);
}
@CrossOrigin
...
...
src/main/java/fr/univnantes/webandcloud/api/controllers/v1/Users.java
View file @
02faec66
...
...
@@ -55,7 +55,7 @@ public class Users extends BaseController {
Cursor
cursorObject
=
cursor
!=
null
?
Cursor
.
fromUrlSafe
(
cursor
)
:
null
;
if
(
userName
!=
null
)
return
userDB
.
searchWithUserNameStartsWith
(
limit
,
cursorObject
,
userName
);
return
userDB
.
getAll
(
limit
,
cursorObject
);
return
userDB
.
getAll
WithoutLinks
(
limit
,
cursorObject
);
}
@CrossOrigin
...
...
src/main/java/fr/univnantes/webandcloud/api/services/DBService.java
View file @
02faec66
...
...
@@ -355,6 +355,17 @@ public class DBService<EntityUsed extends WithIdentifier> extends ServiceUsingDa
return
new
WithCursor
<>(
entities
,
queryResult
.
getCursorAfter
());
}
public
WithCursor
<
List
<
EntityUsed
>>
searchWithoutLinksWith
(
Integer
limit
,
Cursor
lastCursor
,
OrderBy
[]
orders
,
Filter
...
filters
)
{
List
<
EntityUsed
>
entities
=
new
ArrayList
<>();
QueryResults
<
Entity
>
queryResult
=
getDatastore
().
run
(
buildQuery
(
Query
.
newEntityQueryBuilder
(),
limit
,
lastCursor
,
orders
,
filters
));
while
(
queryResult
.
hasNext
())
{
entities
.
add
(
utils
.
createFromEntityWithoutLinks
(
queryResult
.
next
()));
}
return
new
WithCursor
<>(
entities
,
queryResult
.
getCursorAfter
());
}
public
WithCursor
<
EntityUsed
>
searchFirstWith
(
EntityUsed
entity
,
FilterFieldOf
<
EntityUsed
>...
filterFieldOfs
)
{
return
searchFirstWith
(
getFieldOf
(
entity
,
filterFieldOfs
));
}
...
...
@@ -509,4 +520,36 @@ public class DBService<EntityUsed extends WithIdentifier> extends ServiceUsingDa
public
WithCursor
<
List
<
EntityUsed
>>
getAll
(
Integer
limit
,
Cursor
lastCursor
,
OrderBy
...
orders
)
{
return
searchWith
(
limit
,
lastCursor
,
orders
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
()
{
return
getAllWithoutLinks
(
null
,
(
Cursor
)
null
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Integer
limit
)
{
return
getAllWithoutLinks
(
limit
,
(
Cursor
)
null
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Cursor
lastCursor
)
{
return
getAllWithoutLinks
(
null
,
lastCursor
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
OrderBy
...
orders
)
{
return
getAllWithoutLinks
(
null
,
null
,
orders
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Integer
limit
,
Cursor
lastCursor
)
{
return
getAllWithoutLinks
(
limit
,
lastCursor
,
new
OrderBy
[
0
]);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Integer
limit
,
OrderBy
...
orders
)
{
return
getAllWithoutLinks
(
limit
,
null
,
orders
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Cursor
lastCursor
,
OrderBy
...
orders
)
{
return
getAllWithoutLinks
(
null
,
lastCursor
,
orders
);
}
public
WithCursor
<
List
<
EntityUsed
>>
getAllWithoutLinks
(
Integer
limit
,
Cursor
lastCursor
,
OrderBy
...
orders
)
{
return
searchWithoutLinksWith
(
limit
,
lastCursor
,
orders
);
}
}
src/main/java/fr/univnantes/webandcloud/api/services/db/DBPost.java
View file @
02faec66
...
...
@@ -52,4 +52,10 @@ public class DBPost extends DBAncestorService<Post, User> {
ordersList
.
add
(
createdDesc
);
return
getAll
(
limit
,
lastCursor
,
ordersList
.
toArray
(
new
OrderBy
[
ordersList
.
size
()]));
}
public
WithCursor
<
List
<
Post
>>
getAllCreatedDescWithoutLinks
(
Integer
limit
,
Cursor
lastCursor
,
OrderBy
...
orders
)
{
List
<
OrderBy
>
ordersList
=
new
ArrayList
<>(
Arrays
.
asList
(
orders
));
ordersList
.
add
(
createdDesc
);
return
getAllWithoutLinks
(
limit
,
lastCursor
,
ordersList
.
toArray
(
new
OrderBy
[
ordersList
.
size
()]));
}
}
src/main/java/fr/univnantes/webandcloud/api/services/utils/PostUtils.java
View file @
02faec66
...
...
@@ -102,7 +102,7 @@ public class PostUtils extends AncestorUtils<Post, User> {
try
{
Date
postTime
=
entity
.
getTimestamp
(
"postTime"
).
toDate
();
return
new
Post
(
entity
.
getKey
().
getName
(),
uri
,
msg
,
title
,
postTime
,
getAncestorWithoutLinks
(
entity
),
n
ew
ArrayList
<>()
);
getAncestorWithoutLinks
(
entity
),
n
ull
);
}
catch
(
DatastoreException
ignored
)
{
throw
new
RuntimeException
(
String
.
format
(
"Integrity error of post %s (postTime missing)"
,
entity
.
getKey
().
getName
()));
...
...
src/main/java/fr/univnantes/webandcloud/api/services/utils/UserUtils.java
View file @
02faec66
...
...
@@ -93,8 +93,10 @@ public class UserUtils extends BaseUtils<User> {
if
(
instance
.
getUri
()
!=
null
)
builder
.
set
(
"uri"
,
instance
.
getUri
());
builder
.
set
(
"email"
,
instance
.
getEmail
());
updateFollows
(
instance
);
updateLikes
(
instance
);
if
(
instance
.
getFollows
()
!=
null
)
updateFollows
(
instance
);
if
(
instance
.
getLikedPosts
()
!=
null
)
updateLikes
(
instance
);
return
builder
;
}
...
...
@@ -139,7 +141,7 @@ public class UserUtils extends BaseUtils<User> {
String
userName
=
entity
.
getString
(
"userName"
);
try
{
String
email
=
entity
.
getString
(
"email"
);
return
new
User
(
entity
.
getKey
().
getName
(),
userName
,
email
,
uri
);
return
new
User
(
entity
.
getKey
().
getName
(),
userName
,
email
,
uri
,
null
,
null
,
null
);
}
catch
(
DatastoreException
ignored
)
{
throw
new
RuntimeException
(
String
.
format
(
"Integrity error of user %s (email missing)"
,
entity
.
getKey
().
getName
()));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment