Skip to content

Commit aa4b282

Browse files
authored
RSDEV-148: performance of API document search (#55)
* rather than filtering all records by permission, which is a performance hit, only filter in the case where the viewable user of the user performing a search is a PI. In this case, the searching user should only see docs shared with the group, as oppose to all of the group member PIs work, which is the case for regular users. Also some code cleanup * use list of users as sql query input rather than looping through each user and performing a sql query for each when getting all of a users records. apply search terms to records list before determining which records can be viewed by the subject user to increase performance * replace inefficient check on permissions based on whether owing user is a pi with single check after getting all records using new query which takes a list of user ids. only checks permissions if the owning user is a pi which is the only case where the subject user may not be allowed to view
1 parent c894832 commit aa4b282

15 files changed

+217
-343
lines changed

src/main/java/com/researchspace/api/v1/controller/DocumentsApiController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public ApiDocumentSearchResult getDocuments(
144144
* Converting search results to ApiSearchResult
145145
*/
146146
ApiDocumentSearchResult searchResult = new ApiDocumentSearchResult();
147-
List<ApiDocumentInfo> info = new ArrayList<ApiDocumentInfo>();
147+
List<ApiDocumentInfo> info = new ArrayList<>();
148148
convertISearchResults(
149149
pgCrit,
150150
srchConfig,

src/main/java/com/researchspace/dao/RecordDao.java

+13-59
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public interface RecordDao extends GenericDao<Record, Long> {
2323
*
2424
* @param parentId - The Id of the record whose child records we need to retrieve.
2525
* @param pgCrit Pagination Criteria
26-
* @param recordTypefilter
2726
* @return An {@link ISearchResults} object.
2827
*/
2928
ISearchResults<BaseRecord> getPaginatedChildRecordsOfParentWithFilter(
@@ -35,9 +34,6 @@ ISearchResults<BaseRecord> getPaginatedChildRecordsOfParentWithFilter(
3534
* Retrieves a list of ids of all the visible, non-deleted, normal (i.e., not templates)
3635
* structured documents belonging to a parent folder id. The ids are all ordered by creation date
3736
* ascending, i.e., oldest entries first.
38-
*
39-
* @param parentId
40-
* @return
4137
*/
4238
List<Long> getNotebookContentsExcludeFolders(Long parentId);
4339

@@ -46,7 +42,6 @@ ISearchResults<BaseRecord> getPaginatedChildRecordsOfParentWithFilter(
4642
*
4743
* @param users A collection of users to order
4844
* @param pgCrit PAgination criteria for sorting purposes
49-
* @return
5045
*/
5146
Map<String, DatabaseUsageByUserGroupByResult> getTotalRecordsForUsers(
5247
Collection<User> users, PaginationCriteria<User> pgCrit);
@@ -60,12 +55,7 @@ Map<String, DatabaseUsageByUserGroupByResult> getTotalRecordsForUsers(
6055
Map<String, DatabaseUsageByUserGroupByResult> getTotalRecordsForUsers(
6156
PaginationCriteria<User> pgCrit);
6257

63-
/**
64-
* Gets record in the database related with field
65-
*
66-
* @param fieldId
67-
* @return
68-
*/
58+
/** Gets record in the database related with field */
6959
BaseRecord getRecordFromFieldId(long fieldId);
7060

7161
Long getCountOfUsersWithRecords();
@@ -91,40 +81,26 @@ Map<String, DatabaseUsageByUserGroupByResult> getTotalRecordsForUsers(
9181
*/
9282
List<RSpaceDocView> getRecordViewsById(Set<Long> dbids);
9383

94-
/**
95-
* Get records by id, from a list of Ids.
96-
*
97-
* @param dbids
98-
* @return
99-
*/
84+
/** Get records by id, from a list of Ids. */
10085
List<Record> getRecordsById(List<Long> dbids);
10186

10287
/**
103-
* Gets all viewable records belonging to the user. This method does <em>not</em> return items
104-
* belonging to other users.
105-
*
106-
* @param user
107-
* @return
88+
* Gets all viewable records belonging to the set of users. This method does <em>not</em> return
89+
* items belonging to other users.
10890
*/
109-
Set<BaseRecord> getViewableRecordsForUser(User user);
91+
Set<BaseRecord> getViewableRecordsForUsers(Set<Long> userIds);
11092

11193
/**
112-
* Gets all viewable templates belonging to the user. This method does <em>not</em> return items
113-
* belonging to other users.
114-
*
115-
* @param user
116-
* @return
94+
* Gets all viewable templates belonging to the set of users. This method does <em>not</em> return
95+
* items belonging to other users.
11796
*/
118-
Set<BaseRecord> getViewableTemplatesForUser(User user);
97+
Set<BaseRecord> getViewableTemplatesForUsers(Set<Long> userIds);
11998

12099
/**
121-
* Gets all viewable media files belonging to the user. This method does <em>not</em> return items
122-
* belonging to other users.
123-
*
124-
* @param user
125-
* @return
100+
* Gets all viewable media files belonging to the set of users. This method does <em>not</em>
101+
* return items belonging to other users.
126102
*/
127-
Set<BaseRecord> getViewableMediaFiles(User user);
103+
Set<BaseRecord> getViewableMediaFiles(Set<Long> userIds);
128104

129105
/** Tests if BaseRecord with id is a Record or not */
130106
boolean isRecord(Long id);
@@ -144,8 +120,6 @@ List<String> getTextDataFromOntologyFilesOwnedByUserIfSharedWithAGroup(
144120
* If <code>admin</code> is linked to a community, gets all tags in documents created by users of
145121
* that community. Otherwise, returns an empty set.
146122
*
147-
* @param admin
148-
* @param tagSearch
149123
* @return A list of docTag values (these may contain multiple individual tags)
150124
*/
151125
List<String> getTagsMetaDataForRecordsVisibleByCommunityAdmin(User admin, String tagSearch);
@@ -155,7 +129,6 @@ List<String> getTextDataFromOntologyFilesOwnedByUserIfSharedWithAGroup(
155129
/**
156130
* Gets some metadata of Documents that link to a media file
157131
*
158-
* @param mediaFileId
159132
* @return a possibly empty but non-null List
160133
*/
161134
List<RecordInformation> getInfosOfDocumentsLinkedToMediaFile(Long mediaFileId);
@@ -166,43 +139,24 @@ List<String> getTextDataFromOntologyFilesOwnedByUserIfSharedWithAGroup(
166139
* RSPAC-1735) in the same transaction, whereby hibernate occasionally does not issue an SQL
167140
* 'delete from RecordToFolder' from old folder <em>In general use RecordManager#move to move
168141
* items around </em>
169-
*
170-
* @param toUpdate
171-
* @param newFolderId
172-
* @return
173142
*/
174143
int updateRecordToFolder(RecordToFolder toUpdate, Long newFolderId);
175144

176-
/**
177-
* Get the ids of not-deleted notebooks belonging to the user
178-
*
179-
* @param user
180-
* @return
181-
*/
145+
/** Get the ids of not-deleted notebooks belonging to the user */
182146
List<Long> getAllNotebookIdsOwnedByUser(User user);
183147

184148
/**
185149
* Gets ids of all not-deleted StructuredDocuments that are in notebooks, where both the documents
186150
* and notebooks are owned by the user
187-
*
188-
* @param user
189-
* @return
190151
*/
191152
List<Long> getAllDocumentIdsInNotebooksForUser(User user);
192153

193-
/**
194-
* Gets the ids of all not-deleted Structured Documents owned by the user.
195-
*
196-
* @param user
197-
* @return
198-
*/
154+
/** Gets the ids of all not-deleted Structured Documents owned by the user. */
199155
List<Long> getAllNonTemplateNonTemporaryStrucDocIdsOwnedByUser(User user);
200156

201157
/**
202158
* Gets not-deleted document count for a user, based on filter.
203159
*
204-
* @param recordTypes
205-
* @param user
206160
* @return the number of documents owned by the user, of the specified types
207161
*/
208162
Long getRecordCountForUser(RecordTypeFilter recordTypes, User user);

0 commit comments

Comments
 (0)