-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Kirch
authored
Sep 14, 2023
1 parent
eedf19a
commit ab7ff25
Showing
29 changed files
with
484 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
docs-core/src/main/java/com/sismics/docs/core/service/FileSizeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.sismics.docs.core.service; | ||
|
||
import com.google.common.util.concurrent.AbstractScheduledService; | ||
import com.sismics.docs.core.dao.FileDao; | ||
import com.sismics.docs.core.dao.UserDao; | ||
import com.sismics.docs.core.model.jpa.File; | ||
import com.sismics.docs.core.model.jpa.User; | ||
import com.sismics.docs.core.util.FileUtil; | ||
import com.sismics.docs.core.util.TransactionUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Service that retrieve files sizes when they are not in the database. | ||
*/ | ||
public class FileSizeService extends AbstractScheduledService { | ||
/** | ||
* Logger. | ||
*/ | ||
private static final Logger log = LoggerFactory.getLogger(FileSizeService.class); | ||
|
||
public FileSizeService() { | ||
} | ||
|
||
@Override | ||
protected void startUp() { | ||
log.info("File size service starting up"); | ||
} | ||
|
||
@Override | ||
protected void shutDown() { | ||
log.info("File size service shutting down"); | ||
} | ||
|
||
private static final int BATCH_SIZE = 30; | ||
|
||
@Override | ||
protected void runOneIteration() { | ||
try { | ||
TransactionUtil.handle(() -> { | ||
FileDao fileDao = new FileDao(); | ||
List<File> files = fileDao.getFilesWithUnknownSize(BATCH_SIZE); | ||
for(File file : files) { | ||
processFile(file); | ||
} | ||
if(files.size() < BATCH_SIZE) { | ||
log.info("No more file to process, stopping the service"); | ||
stopAsync(); | ||
} | ||
}); | ||
} catch (Throwable e) { | ||
log.error("Exception during file service iteration", e); | ||
} | ||
} | ||
|
||
void processFile(File file) { | ||
UserDao userDao = new UserDao(); | ||
User user = userDao.getById(file.getUserId()); | ||
if(user == null) { | ||
return; | ||
} | ||
|
||
long fileSize = FileUtil.getFileSize(file.getId(), user); | ||
if(fileSize != File.UNKNOWN_SIZE){ | ||
FileDao fileDao = new FileDao(); | ||
file.setSize(fileSize); | ||
fileDao.update(file); | ||
} | ||
} | ||
|
||
@Override | ||
protected Scheduler scheduler() { | ||
return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.MINUTES); | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
docs-core/src/main/java/com/sismics/docs/core/service/InboxService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
docs-core/src/main/java/com/sismics/docs/core/util/format/TextPlainFormatHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
db.version=28 | ||
db.version=29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table T_FILE add column FIL_SIZE_N bigint not null default -1; | ||
update T_CONFIG set CFG_VALUE_C = '29' where CFG_ID_C = 'DB_VERSION'; |
Oops, something went wrong.