mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-28 04:47:42 +03:00
optional time constraint when listing sessions. project home loads only last 4 days
This commit is contained in:
parent
60e85f509f
commit
38860ded04
@ -176,10 +176,11 @@ async fn search(
|
||||
async fn list_sessions(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: &str,
|
||||
earliest_timestamp_ms: Option<u128>,
|
||||
) -> Result<Vec<sessions::Session>, Error> {
|
||||
let repo = repo_for_project(handle, project_id)?;
|
||||
let sessions = repo
|
||||
.sessions()
|
||||
.sessions(earliest_timestamp_ms)
|
||||
.with_context(|| format!("Failed to list sessions for project {}", project_id))?;
|
||||
|
||||
Ok(sessions)
|
||||
@ -708,7 +709,7 @@ fn debug_test_consistency(app_state: &App, project_id: &str) -> Result<()> {
|
||||
project_id,
|
||||
)?;
|
||||
|
||||
let sessions = repo.sessions()?;
|
||||
let sessions = repo.sessions(None)?;
|
||||
let session_deltas: Vec<HashMap<String, Vec<Delta>>> = sessions
|
||||
.iter()
|
||||
.map(|session| {
|
||||
|
@ -54,8 +54,8 @@ impl Repository {
|
||||
Ok(reference)
|
||||
}
|
||||
|
||||
pub fn sessions(&self) -> Result<Vec<sessions::Session>> {
|
||||
sessions::list(&self.git_repository, &self.project, &self.reference()?)
|
||||
pub fn sessions(&self, earliest_timestamp_ms: Option<u128>) -> Result<Vec<sessions::Session>> {
|
||||
sessions::list(&self.git_repository, &self.project, &self.reference()?, earliest_timestamp_ms)
|
||||
}
|
||||
|
||||
pub fn files(
|
||||
|
@ -402,8 +402,9 @@ pub fn list(
|
||||
repo: &git2::Repository,
|
||||
project: &projects::Project,
|
||||
reference: &git2::Reference,
|
||||
earliest_timestamp_ms: Option<u128>,
|
||||
) -> Result<Vec<Session>> {
|
||||
let mut sessions = list_persistent(repo, reference)?;
|
||||
let mut sessions = list_persistent(repo, reference, earliest_timestamp_ms)?;
|
||||
if let Some(session) = Session::current(repo, project)? {
|
||||
sessions.insert(0, session);
|
||||
}
|
||||
@ -414,7 +415,7 @@ pub fn list(
|
||||
// except for the first session. The first created session
|
||||
// is special and used to bootstrap the gitbutler state inside a repo.
|
||||
// see crate::repositories::init
|
||||
fn list_persistent(repo: &git2::Repository, reference: &git2::Reference) -> Result<Vec<Session>> {
|
||||
fn list_persistent(repo: &git2::Repository, reference: &git2::Reference, earliest_timestamp_ms: Option<u128>) -> Result<Vec<Session>> {
|
||||
let head = repo.find_commit(reference.target().unwrap())?;
|
||||
|
||||
// list all commits from gitbutler head to the first commit
|
||||
@ -433,6 +434,14 @@ fn list_persistent(repo: &git2::Repository, reference: &git2::Reference) -> Resu
|
||||
)
|
||||
})?;
|
||||
let session = Session::from_commit(repo, &commit)?;
|
||||
match earliest_timestamp_ms {
|
||||
Some(earliest_timestamp_ms) => {
|
||||
if session.meta.start_timestamp_ms <= earliest_timestamp_ms {
|
||||
break;
|
||||
}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
sessions.push(session);
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ fn test_list() {
|
||||
let current = current_session.unwrap();
|
||||
|
||||
let reference = repo.find_reference(&project.refname()).unwrap();
|
||||
let sessions = super::sessions::list(&repo, &project, &reference);
|
||||
let sessions = super::sessions::list(&repo, &project, &reference, None);
|
||||
assert!(sessions.is_ok());
|
||||
let sessions = sessions.unwrap();
|
||||
|
||||
|
@ -115,7 +115,7 @@ fn test_flow() {
|
||||
.git_repository
|
||||
.find_reference(&repo.project.refname())
|
||||
.unwrap();
|
||||
let mut sessions = sessions::list(&repo.git_repository, &repo.project, &reference).unwrap();
|
||||
let mut sessions = sessions::list(&repo.git_repository, &repo.project, &reference, None).unwrap();
|
||||
assert_eq!(sessions.len(), size);
|
||||
|
||||
// verify sessions order is correct
|
||||
|
@ -34,7 +34,7 @@ export const listFiles = (params: { projectId: string; sessionId: string; paths?
|
||||
|
||||
const list = (params: { projectId: string }) => invoke<Session[]>('list_sessions', params);
|
||||
|
||||
export default async (params: { projectId: string }) => {
|
||||
export default async (params: { projectId: string, earliestTimestampMs?: number }) => {
|
||||
const store = writable([] as Session[]);
|
||||
list(params).then((sessions) => {
|
||||
store.set(sessions);
|
||||
|
@ -4,6 +4,7 @@ import { readable, derived } from 'svelte/store';
|
||||
import type { Session } from '$lib/sessions';
|
||||
import type { Status } from '$lib/statuses';
|
||||
import type { Activity } from '$lib/sessions';
|
||||
import { subDays, getTime } from 'date-fns';
|
||||
|
||||
export const prerender = false;
|
||||
export const load: LayoutLoad = async ({ parent, params }) => {
|
||||
@ -13,13 +14,18 @@ export const load: LayoutLoad = async ({ parent, params }) => {
|
||||
? readable<Status[]>([])
|
||||
: await (await import('$lib/statuses')).default({ projectId: params.projectId });
|
||||
|
||||
const sessions = building
|
||||
const sessionsFromLastFourDays = building
|
||||
? readable<Session[]>([])
|
||||
: await (await import('$lib/sessions')).default({ projectId: params.projectId });
|
||||
const orderedSessions = derived(sessions, (sessions) => {
|
||||
: await (
|
||||
await import('$lib/sessions')
|
||||
).default({
|
||||
projectId: params.projectId,
|
||||
earliestTimestampMs: getTime(subDays(new Date(), 4))
|
||||
});
|
||||
const orderedSessionsFromLastFourDays = derived(sessionsFromLastFourDays, (sessions) => {
|
||||
return sessions.slice().sort((a, b) => a.meta.startTimestampMs - b.meta.startTimestampMs);
|
||||
});
|
||||
const recentActivity = derived(sessions, (sessions) => {
|
||||
const recentActivity = derived(sessionsFromLastFourDays, (sessions) => {
|
||||
const recentActivity: Activity[] = [];
|
||||
sessions.forEach((session) => {
|
||||
session.activity.forEach((activity) => {
|
||||
@ -35,7 +41,7 @@ export const load: LayoutLoad = async ({ parent, params }) => {
|
||||
return {
|
||||
project: projects.get(params.projectId),
|
||||
projectId: params.projectId,
|
||||
sessions: orderedSessions,
|
||||
orderedSessionsFromLastFourDays: orderedSessionsFromLastFourDays,
|
||||
filesStatus: filesStatus,
|
||||
recentActivity: recentActivity
|
||||
};
|
||||
|
@ -16,14 +16,14 @@
|
||||
$: project = data.project;
|
||||
$: filesStatus = data.filesStatus;
|
||||
$: recentActivity = data.recentActivity as Readable<Activity[]>;
|
||||
$: sessions = data.sessions;
|
||||
$: orderedSessionsFromLastFourDays = data.orderedSessionsFromLastFourDays;
|
||||
|
||||
let latestDeltasByDateByFile: Record<number, Record<string, Delta[][]>[]> = {};
|
||||
|
||||
$: if ($project) {
|
||||
latestDeltasByDateByFile = {};
|
||||
const dateSessions: Record<number, Session[]> = {};
|
||||
$sessions.forEach((session) => {
|
||||
$orderedSessionsFromLastFourDays.forEach((session) => {
|
||||
const date = startOfDay(new Date(session.meta.startTimestampMs));
|
||||
if (dateSessions[date.getTime()]) {
|
||||
dateSessions[date.getTime()]?.push(session);
|
||||
|
Loading…
Reference in New Issue
Block a user